We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
interface Interface { [id: string]: string; } var a:Interface = { b: 'foo' }; a.b = 'bar';
Throws an error:
Property 'b' does not exist on type 'Interface'
Possible to solve? Maybe treat Array index as 'any':
var a:any = {}; a.b= "foobar";
This one is ok.
The text was updated successfully, but these errors were encountered:
to access the member b you need to define it in the interface. e.g:
b
interface Interface { b: string; } var a:Interface; a.b = 'bar'; // OK
alternatively you can use string indexing to access your property:
interface Interface { [id: string]: string; } var a:Interface; a["b"] = 'bar'; // OK, type of a["b"] is defined in the string indexer definition in Interface
if you give a value the type any, it can have any number of properties, and the compiler will not enforce any rules there.
any
Sorry, something went wrong.
No branches or pull requests
Throws an error:
Possible to solve? Maybe treat Array index as 'any':
This one is ok.
The text was updated successfully, but these errors were encountered: