Members of the Same Type
This lesson explains how to have members in a type defined with an index signature.
We'll cover the following...
Same type
The interface defined by members and an index type that uses a string as the key must have all its members to be of type string.
πNote: the code below throws an error β
Press + to interact
interface MyStringDictionaryWithMembers {[key: string]: string;m1: string;m2: number; // Won't transpile, must be a string}
If we correct the previous example to have m2
to be a string
on line 4, the code ...