We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
type guard get property const
Fails at least on 4.3.5 and 4.4.0-beta.
Playground link with relevant code
const x: string | number = Math.random() < 0.5 ? "str" : 123; if (typeof x === "string") { let obj = { get prop() { return x.toUpperCase() }, // Error: property toUpperCase doesn't exist on number method() { return x.toUpperCase() } // Ok } }
The method compiles, the getter raises an error.
Behaviour should be the same for both. Given that x is a const and its type was narrowed to string, no error seems right.
x
string
The text was updated successfully, but these errors were encountered:
should control flow flow into setters, too?
Sorry, something went wrong.
@softwareCobbler Yes.
const x: string | null = "abc"; if (x) { const obj = { // Following is valid and should not warn that x might be null set test(val) { console.log(x.toUpperCase(); } } }
Successfully merging a pull request may close this issue.
Bug Report
π Search Terms
type guard get property const
π Version & Regression Information
Fails at least on 4.3.5 and 4.4.0-beta.
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The method compiles, the getter raises an error.
π Expected behavior
Behaviour should be the same for both.
Given that
x
is a const and its type was narrowed tostring
, no error seems right.The text was updated successfully, but these errors were encountered: