Skip to content

Instantly share code, notes, and snippets.

@mmcc
Created March 29, 2018 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmcc/b482fe720749db174492dd952155d4e1 to your computer and use it in GitHub Desktop.
Save mmcc/b482fe720749db174492dd952155d4e1 to your computer and use it in GitHub Desktop.
Simple example to show an issue with array index access.
interface IGenericThing {
bop: [string, string, string];
[key: string]: string | number | [string, string, string];
}
const foo: IGenericThing = {
bar: '#0000ff',
baz: 123,
bat: ['a', 'b', 'c'],
bop: ['d', 'e', 'f'],
};
const boo: IGenericThing = {
bleep: foo.baz,
bloop: foo.bat[0],
blergh: foo.bop[0],
}
// `blergh` is fine, but `bloop` will error
// Element implicitly has an 'any' type because type 'string | number | [string, string, string]' has no index signature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment