Stricter generic signature checks#16368
Merged
ahejlsberg merged 15 commits intomasterfrom Jun 12, 2017
Merged
Conversation
Member
Author
|
@Aleksey-Bykov Now you can retire the shirt! |
|
@ahejlsberg this is one of all time grand features of TS since unions, type guards and exhaustive switches, it brings point free programming style like what you can find in big boy's FP languages, thank you for your hard work and consideration |
Contributor
gcnew
reviewed
Jun 9, 2017
src/compiler/checker.ts
Outdated
| } | ||
| } | ||
| else if (sourceSignatures.length === 1 && targetSignatures.length === 1) { | ||
| // For pure functions (functions with a single signature) we only erase type parameters for |
Contributor
There was a problem hiding this comment.
Maybe simple/just/only functions would be a better name than pure, as pure brings a different connotation.
# Conflicts: # src/compiler/checker.ts
Member
Author
|
Latest commits add a |
mhegazy
approved these changes
Jun 12, 2017
This was referenced Aug 17, 2017
Merged
This was referenced Aug 21, 2017
rkirov
added a commit
to rkirov/zone.js
that referenced
this pull request
Oct 11, 2017
Due to stricter generic type checks, signatures for ZoneAwarePromise need to be changed. See microsoft/TypeScript#16368 The signatures from lib.es5.d.ts were copied over for .then and .catch.
rkirov
added a commit
to rkirov/zone.js
that referenced
this pull request
Oct 11, 2017
Due to stricter generic type checks, signatures for ZoneAwarePromise need to be changed. See microsoft/TypeScript#16368 The signatures from lib.es5.d.ts were copied over for .then and .catch.
rkirov
added a commit
to rkirov/zone.js
that referenced
this pull request
Oct 12, 2017
Due to stricter generic type checks, signatures for ZoneAwarePromise need to be changed. See microsoft/TypeScript#16368 The signatures from lib.es5.d.ts were copied over for .then and .catch.
mhevery
pushed a commit
to angular/zone.js
that referenced
this pull request
Dec 27, 2017
Due to stricter generic type checks, signatures for ZoneAwarePromise need to be changed. See microsoft/TypeScript#16368 The signatures from lib.es5.d.ts were copied over for .then and .catch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR complements #16305 by implementing stricter checking of type relationships for generic signatures. Previously, when checking type relationships for generic signatures we would always first erase type parameters (by substituting type
anyfor the type parameters). Now, we properly unify the type parameters by first inferring from the target signature to the source signature and then instantiating the source signature with the inferences. For example:Previously, no errors were reported above because
S,T, andUwere replaced byany, causing the signatures to become identical. Now, once we unify the type parameters we can correctly determine thatAis assignable toB, but not vice versa. Specifically, in the first assignment we inferT | UforSwhich after instantiation yields a signature that isn't assignable toA, whereas in the second assignment we inferSfor each ofTandUwhich after instantiation yields the same signature asB.Note that we perform unification only when the source and target types each have a single signature. When either the source or target has multiple signatures (i.e. overloads) we still resort to type parameter erasure as it otherwise becomes prohibitively expensive to determine the relationships.
This PR is technically a breaking change as we now uncover errors we previously wouldn't catch. For this reason we have included a
--noStrictGenericCheckscompiler option to disable the stricter generic signature checks. Existing projects can use this as a stopgap solution until errors resulting from the stricter checking are corrected.Fixes #138, #3410, #5616.