-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Type narrowing by construct signature of interface or object type literal #2969
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
Type narrowing by construct signature of interface or object type literal #2969
Conversation
if (constructorSignitures) { | ||
let constructorType = getUnionType(map(constructorSignitures, constructorSignature => { | ||
if (constructorSignature.typeParameters && constructorSignature.typeParameters.length !== 0) { | ||
// TODO convert type parameters to any or empty object types. e.g. Sample<T> -> Sample<any> or Sample<{}>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't found way to instantiate type parameters. e.g. B<T>
to B<any>
.
the way is not exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instantiateSignature?
@mhegazy thank you for your advice! |
👍 |
if (isTypeSubtypeOf(targetType, type)) { | ||
return targetType; | ||
// Target type is type of constructor signiture | ||
let constructSignitures: Signature[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructSignitures
-> constructSignatures
@DanielRosenwasser thank you for your comment! |
} | ||
// If the current type is a union type, remove all constituents that aren't subtypes of the target. | ||
if (type.flags & TypeFlags.Union) { | ||
return getUnionTypeOfSubtypeConstituents(<UnionType>type, targetType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a huge fan of this name. I've talked it over with @mhegazy and @DanielRosenwasser, and it's probably better to keep this line as it was, instead of factoring it out.
@DanielRosenwasser Thank you very much to me to corrections of my English. |
2d51618
to
f5bcbbc
Compare
f5bcbbc
to
776f390
Compare
wow, travis ci failed... |
@vvakame i ran into that yesterday. i think it is related to a change @JsonFreeman did, not sure if what you are seeing is correct the behavior or not. |
@vvakame where are you seeing test failures? Right now Travis is saying that the tests are passing. |
@mhegazy @DanielRosenwasser https://travis-ci.org/Microsoft/TypeScript/builds/61452430 this is it. |
👍 |
Thanks! |
yay! 😸 Thanks for a lot of supports! |
implement #1283