Skip to content

Instantly share code, notes, and snippets.

@rakia
Created November 27, 2020 19:22
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 rakia/4a844b0b8931ef2f813e7ec36bd55704 to your computer and use it in GitHub Desktop.
Save rakia/4a844b0b8931ef2f813e7ec36bd55704 to your computer and use it in GitHub Desktop.
Typescript noUncheckedIndexedAccess
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