-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed as not planned
Closed as not planned
Copy link
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Bug Report
🔎 Search Terms
Array<T>- const integer index
- not overflow index
- indicate element type from array and array index
- array element type might be undefined
🕗 Version & Regression Information
- This is a crash
- This changed between versions ______ and _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______
⏯ Playground Link
Playground link with relevant code
💻 Code
function fn(s: string) {
console.log(s)
}
function reproduce(input: string[]) {
switch (reproduce.length) {
case 0 as const:
case 1 as const:
fn(input[0 as const])
break
default:
break
}
}
const input: string[] = []
switch (input.length) {
case 0 as const:
case 1 as const:
fn(input[0 as const])
break
default:
break
}🙁 Actual behavior
// fn(input[0 as const])
Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
Type 'undefined' is not assignable to type 'string'.🙂 Expected behavior
// fn(input[0 as const])
OKAdditional
I guess there is already an issue.
But seems not easy to find which to track on from tons of issues.
Metadata
Metadata
Assignees
Labels
DeclinedThe issue was declined as something which matches the TypeScript visionThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScriptAn idea for TypeScript