You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
interfaces are open to extension, whereas types are not. In turn, this means that interfaces do not have index signatures (unlike types), which causes problems when you try to pass an interface into a function which expects an index signature. This is due to a design limitation: microsoft/TypeScript#15300.
For this reason I would recommend using types instead, or adding an explicit index signature to the interface, so that the CSS module type can be passed into a function expecting an index signature.
typeObjectWithStrings={[key: string]: string}declareconstrequireObjectStrings: <TextendsObjectWithStrings>(object: T)=>void;interfaceMyInterface{foo: string;}declareconstmyInterface: MyInterface;// Error: Index signature is missing in type 'MyInterface'.requireObjectStrings(myInterface)typeMyType={foo: string;}declareconstmyType: MyType;// No error, good :-)requireObjectStrings(myType)
The text was updated successfully, but these errors were encountered:
typeObjectWithStrings<Keyextendsstring>=Record<Key,string>declareconstrequireObjectStrings: <Keyextendsstring>(object: ObjectWithStrings<Key>)=>void;interfaceMyInterface{foo: string;}declareconstmyInterface: MyInterface;// No error, good :-)requireObjectStrings(myInterface)
interface
s are open to extension, whereastype
s are not. In turn, this means thatinterface
s do not have index signatures (unliketype
s), which causes problems when you try to pass an interface into a function which expects an index signature. This is due to a design limitation: microsoft/TypeScript#15300.For this reason I would recommend using
type
s instead, or adding an explicit index signature to theinterface
, so that the CSS module type can be passed into a function expecting an index signature.The text was updated successfully, but these errors were encountered: