3 ms·
https://www.typescriptlang.org/play/index.html#code/MYewdgzgLgBAHjAvDA2gRgDQCYC6MCGEMokUA3AFAnQwCeS8KAbCzpdbAF4P0DUMAZjJA https://www.typescriptlang.org/play/in
by scottlecrab 7y ago
https://www.typescriptlang.org/play/index.html#code/MYewdgzgLgBAHjAvDA2gRgDQCYC6MCGEMokUA3AFAnQwCeS8KAbCzpdbAF4P0DUMAZjJA https://www.typescriptlang.org/play/index.html#code/MYewdgzg...
Using `as const` will report both the 2nd and 3rd lines as type errors. You've been able to do this in TypeScript for a while even before they introduced the `as const` syntax.
- seanwilson 7y agoThanks, you can still trick it with this though (there's no type error): const x = [1, 2] as const; const r = 666 + 1; const y = x[r]; const z = y + 3;
- nine_k 7y agoLet's wait until TS supports dependent types!