-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
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
proposal: type guards by constructor signature #1283
Comments
I definitely get the motivation here. One issue is that construct signatures can be generic and/or overloaded. We could probably use the union type of all the construct signatures' return types with |
It's definitely very useful suggestion. 👍 |
+1 for this - well expressed @vvakame |
👍 |
👍 |
1 similar comment
👍 |
@RyanCavanaugh I was misunderstanding spec...
I think this code evaluate to following pseudo code.
but actual
I think this issue is not related to my proposal directly. but I feel "type guards with generics" is very important feature. does we need contextual type guards?
off topic. I'm not using VisualStudio. Is there any way use playgroud of master/HEAD in local environment? off topic 2. if Property_0_does_not_exist_on_type_1 occured after type narrowing check, I want get warning message ("{0} is not narrowed to {1}.") with it. |
Unfortunately there's no easy way to get a playground with the latest bits. One hack you can do to check types via the command line is to redeclare the var whose type you are interested in. That should cause an error which will print the relevant types. |
@danquirk thank you! It very useful information for me. |
Approved |
Thanks @vvakame! |
What does we need?
We need type guards by constructor signature.
Motivation
almost .d.ts files does not have
prototype
property in DefinitelyTyped.It means almost .d.ts files is not union types ready.
I think We can't enforce implement
prototype
property to .d.ts files.Proposal
https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#420-type-guards
modified to
My english is not so good. I made sample code.
The text was updated successfully, but these errors were encountered: