我收到了这个错误:
Type '{ [key: string]: any; }' is not assignable to type 'T'.
'{ [key: string]: any; }' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint '{ [key: string]: any; }'.(2322)
从这段代码:
function getValue ():{[key: string]: any} {
return {key:'value'}
}
class Foo<T extends {[key: string]: any}> {
public readonly data?: T
constructor() {
this.data = getValue()
}
}
有谁知道为什么以及如何解决这个错误?