Bug Report
🔎 Search Terms
narrow, narrowing, getter, unknown
🕗 Version & Regression Information
I noticed this bug on v4.1.2. I can also reproduce it on older versions such as v2.8.1
Please keep and fill in the line that best applies:
- 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 ___ X ____
- I was unable to test this on prior versions because _______
⏯ Playground Link
Playground link with relevant code
💻 Code
function wrap(val: unknown) {
if (typeof val !== 'string') {
throw new Error();
}
console.log(val) // "val" is narrowed to "string" as expected.
return {
getValue() {
return val; // "val" is narrowed to "string" as expected.
},
get value() {
return val; // "val" is still "unknown".
}
}
}
🙁 Actual behavior
The type is not correctly narrowed inside getters.
🙂 Expected behavior
The type to be narrowed inside getters, as is the case for references in other parts of the function.
Bug Report
🔎 Search Terms
narrow, narrowing, getter, unknown
🕗 Version & Regression Information
I noticed this bug on
v4.1.2. I can also reproduce it on older versions such asv2.8.1Please keep and fill in the line that best applies:
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The type is not correctly narrowed inside getters.
🙂 Expected behavior
The type to be narrowed inside getters, as is the case for references in other parts of the function.