Open
Description
🔎 Search Terms
The following typechecks in version 5.8.3 (but shouldn't):
type Endpoints = {
"/foo/bar": {
output: {bar: boolean}
},
"/foo/bar2": {
output: {bar2: boolean}
},
}
function act<Path extends keyof Endpoints>(path: Path): Endpoints[Path]["output"] {
if(path === "/foo/bar") {
return {bar2: true}
}
return {bar: false}
}
const u : {bar: boolean} /* {bar:boolean} is incorrect */ = act("/foo/bar")
console.log(u) // {bar2: true}
🕗 Version & Regression Information
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about version 5.8.3
- I was unable to test this on prior versions because _______
⏯ Playground Link
💻 Code
type Endpoints = {
"/foo/bar": {
output: {bar: boolean}
},
"/foo/bar2": {
output: {bar2: boolean}
},
}
function act<Path extends keyof Endpoints>(path: Path): Endpoints[Path]["output"] {
if(path === "/foo/bar") {
return {bar2: true}
}
return {bar: false}
}
const u : {bar: boolean} /* {bar:boolean} is incorrect */ = act("/foo/bar")
console.log(u) // {bar2: true}
🙁 Actual behavior
It typechecks, but shouldn't. act("/foo/bar")
has the wrong type.
🙂 Expected behavior
I would have expected a type error
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
No labels