Skip to content

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

Merged
merged 5 commits into from
May 6, 2015

Conversation

vvakame
Copy link
Contributor

@vvakame vvakame commented Apr 30, 2015

implement #1283

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<{}>.
Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instantiateSignature?

@vvakame
Copy link
Contributor Author

vvakame commented May 2, 2015

@mhegazy thank you for your advice!
I added a new commit. it support generic types and add some test cases.

@mhegazy
Copy link
Contributor

mhegazy commented May 5, 2015

👍

if (isTypeSubtypeOf(targetType, type)) {
return targetType;
// Target type is type of constructor signiture
let constructSignitures: Signature[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constructSignitures -> constructSignatures

@vvakame
Copy link
Contributor Author

vvakame commented May 5, 2015

@DanielRosenwasser thank you for your comment!
I added a new commit.

}
// 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);
Copy link
Contributor

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.

@vvakame
Copy link
Contributor Author

vvakame commented May 6, 2015

@DanielRosenwasser Thank you very much to me to corrections of my English.
@JsonFreeman thanks! I added a new commit.

@vvakame vvakame changed the title Type narrowing by constructor signiture of interface or object type literal Type narrowing by constructor signature of interface or object type literal May 6, 2015
@vvakame vvakame changed the title Type narrowing by constructor signature of interface or object type literal Type narrowing by construct signature of interface or object type literal May 6, 2015
@vvakame vvakame force-pushed the typeguardsByConstructorSigniture branch from 2d51618 to f5bcbbc Compare May 6, 2015 12:03
@vvakame vvakame force-pushed the typeguardsByConstructorSigniture branch from f5bcbbc to 776f390 Compare May 6, 2015 12:18
@vvakame
Copy link
Contributor Author

vvakame commented May 6, 2015

wow, travis ci failed...
I ran the git config --local core.autocrlf false to cure the test. but why?

@mhegazy
Copy link
Contributor

mhegazy commented May 6, 2015

@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.

@DanielRosenwasser
Copy link
Member

@vvakame where are you seeing test failures? Right now Travis is saying that the tests are passing.

@vvakame
Copy link
Contributor Author

vvakame commented May 6, 2015

@mhegazy @DanielRosenwasser https://travis-ci.org/Microsoft/TypeScript/builds/61452430 this is it.
I found it and fix up & doing push -f about last commit.
please check vvakame@776f390 (without whitespace vvakame@776f390?w=) .
this commit contains change line break character about tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.errors.txt and tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.js.
I think this is bad solution, but Travis CI passed this commit.

@JsonFreeman
Copy link
Contributor

👍

@mhegazy mhegazy merged commit 776f390 into microsoft:master May 6, 2015
@mhegazy
Copy link
Contributor

mhegazy commented May 6, 2015

Thanks!

@vvakame
Copy link
Contributor Author

vvakame commented May 7, 2015

yay! 😸 Thanks for a lot of supports!

@vvakame vvakame deleted the typeguardsByConstructorSigniture branch May 7, 2015 00:54
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants