-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed as not planned
Labels
SuggestionAn idea for TypeScriptAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it addsAn issue which adding support for may be too complex for the value it adds
Description
Search Terms
Indexing, Array, Strict check
Suggestion
Strict check to indexing a array
Use Cases
Safety with arrays usages
Examples
const arr: House[] = .... // same as [] | House[]
arr[0] // throw error
if(arr.length > 0) {
arr[0] // OK
arr[200] // throw error
}
const arr2: [House, House] = ...
arr[0] // OK
arr[1] // OKChecklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code (with a flag)
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
rubenlg, Greg-NetDuma, Amirault, Ky6uk, seanwu1105 and 26 moreRudxain and Norbiros
Metadata
Metadata
Assignees
Labels
SuggestionAn idea for TypeScriptAn idea for TypeScriptToo ComplexAn issue which adding support for may be too complex for the value it addsAn issue which adding support for may be too complex for the value it adds