Is there a way to define a custom type named TestType
that extends the existing BaseType
, while also accepting a generic type as input?
Consider the following code snippet:
type BaseType={
id:number
}
interface TestType<T=any> extends BaseType {
prop1:string;
[key: string]: T;
}
When implementing this code, I encounter an error labeled TS2411
:
Property 'prop1' of type 'string' is not assignable to 'string' index type 'T'.
Any suggestions on how to resolve this issue?