-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Suggestion
The ability to support using explicit types for exact array lengths with JSON data.
π Search Terms
json exact matching array types
β Viability Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- 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, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
β Suggestion
The ability to treat JSON arrays as exact arrays.
π Motivating Example
{"example": [1, 2, "three", 4]}
import thing from 'test.json';
interface Test {
example: [number, number, string, number];
}
export const example: Test = thing;
π» Use Cases
This allows making more-specific rather than less-specific types. In the above example, the compiler will flag the declaration because a (number|string)[]
does not match the specific type I provided.
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created