Created
March 29, 2018 22:52
-
-
Save mmcc/b482fe720749db174492dd952155d4e1 to your computer and use it in GitHub Desktop.
Simple example to show an issue with array index access.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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