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
TypeScript Version: 2.4.0
interface I { data: string } let a: any = {data: 'string'} a as I a.da // Now it should be wrong a.data // There should be smart tips here
We want the type assertion to work on the variable itself in the code block
The text was updated successfully, but these errors were encountered:
Related to #17760?
What I do:
Helper function:
function assert<T>(x: any): x is T { return true; }
Then:
interface I { data: string } let a: any = {data: 'string'} if (!assert<I>(a)) throw null; // like "a as I" a.da // error a.data // smart tips galore
Sorry, something went wrong.
@jcalz This method is valid But converted to Javascript,some become redundant
function assert(x) { return true; } var a = { data: 'string' }; if (!assert(a)) throw null; // like "a as I" a.da; // error a.data; // smart tips galore
if expression will always be correct, it becomes an extra code with assert() I think your method is similar:
interface I { data: string } let a: any = {data: 'string'} let b: I = a
Both of these methods will generate extra Javascript code
Is it possible to have a method that only plays the role of type assertions in the Typescript, without generating extra JavaScript code
Duplicate of #10421
No branches or pull requests
TypeScript Version: 2.4.0
We want the type assertion to work on the variable itself in the code block
The text was updated successfully, but these errors were encountered: