Created
November 27, 2020 19:22
-
-
Save rakia/4a844b0b8931ef2f813e7ec36bd55704 to your computer and use it in GitHub Desktop.
Typescript noUncheckedIndexedAccess
This file contains 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 Options { | |
path: string; | |
permissions: number; | |
// Extra properties are caught by this index signature. | |
[propName: string]: string | number; | |
} | |
function checkOptions(opts: Options) { | |
opts.path; // string | |
opts.permissions; // number | |
// These are all allowed too! | |
// They have the type 'string | number'. | |
opts.yadda.toString(); | |
opts["foo bar baz"].toString(); | |
opts[Math.random()].toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment