| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
TypeScript Bot (@typescript-bot) test this |
Sorry, something went wrong.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the extended test suite on this PR at a0fbf5c. You can monitor the build here. |
Sorry, something went wrong.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the perf test suite on this PR at a0fbf5c. You can monitor the build here. Update: The results are in! |
Sorry, something went wrong.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized Definitely Typed test suite on this PR at a0fbf5c. You can monitor the build here. |
Sorry, something went wrong.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the abridged perf test suite on this PR at a0fbf5c. You can monitor the build here. Update: The results are in! |
Sorry, something went wrong.
|
Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized community code test suite on this PR at a0fbf5c. You can monitor the build here. |
Sorry, something went wrong.
|
Anders Hejlsberg (@ahejlsberg) Comparison Report - master..43183
System
Hosts
Scenarios
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sorry, something went wrong.
|
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
Sorry, something went wrong.
|
Anders Hejlsberg (@ahejlsberg) Comparison Report - master..43183
System
Hosts
Scenarios
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sorry, something went wrong.
| function getConstraintForReference(type: Type, reference: Identifier | ElementAccessExpression | PropertyAccessExpression | QualifiedName, checkMode: CheckMode | undefined) { | ||
| // When the type of a reference is or contains an instantiable type with a union type constraint, and | ||
| // when the reference is in a constraint position (where it is known we'll obtain the apparent type) or | ||
| // has a contextual type containing no instantiables (meaning constraints will determine assignability), |
There was a problem hiding this comment.
| // has a contextual type containing no instantiables (meaning constraints will determine assignability), | |
| // has a contextual type containing no top-level instantiables (meaning constraints will determine assignability), |
or
| // has a contextual type containing no instantiables (meaning constraints will determine assignability), | |
| // has a contextual type containing no immediate instantiables (meaning constraints will determine assignability), |
Sorry, something went wrong.
|
TypeScript Bot (@typescript-bot) pack this |
Sorry, something went wrong.
|
Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the tarball bundle task on this PR at 1a695e9. You can monitor the build here. |
Sorry, something went wrong.
|
Hey Daniel Rosenwasser (@DanielRosenwasser), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so: {
"devDependencies": {
"typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/98224/artifacts?artifactName=tgz&fileId=266017171922858A31CD3EFD83E393EF6E56EB48D53ED8C01365E5A0113A6F5602&fileName=/typescript-4.3.0-insiders.20210310.tgz"
}
}
and then running npm install. There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/pr-build@4.3.0-pr-43183-11".; |
Sorry, something went wrong.
|
Anders Hejlsberg (@ahejlsberg) might be worth adding in the following test cases - f2 now works correctly. interface Box<T> {
item: T;
}
declare function isBox(x: any): x is Box<unknown>;
declare function isUndefined(x: unknown): x is undefined;
declare function unbox<T>(x: Box<T>): T;
function f1<T extends Box<T> | undefined>(x: T) {
if (isBox(x)) {
unbox(x);
}
}
function f2<T extends Box<T> | undefined>(x: T) {
if (!isUndefined(x)) {
unbox(x);
}
}
function f3<T extends Box<T> | undefined>(x: T) {
if (!isBox(x)) {
// error
unbox(x);
}
}
function f4<T extends Box<T> | undefined>(x: T) {
if (isUndefined(x)) {
// error
unbox(x);
}
} |
Sorry, something went wrong.
Sorry, something went wrong.
|
Performance looks to be unaffected. RWC test suite looks good too, only change is a couple of error messages that now show constraint types instead of generic types (as expected). |
Sorry, something went wrong.
TS 4.7 catches a class of error which 4.6 and earlier did not, courtesy of microsoft/TypeScript#43183: if the type passed does not implement `toString()`, it notices, because it no longer defaults to falling back to `{}`. Fixes #330
TS 4.7 catches a class of error which 4.6 and earlier did not, courtesy of microsoft/TypeScript#43183: if the type passed does not implement `toString()`, it notices, because it no longer defaults to falling back to `{}`. To resolve this, *loosen* the constraints on what is acceptable as input to `toString`, by making the implementation itself more robust. Doing so also fixes a bug with the output for `toString` when working with strings: previously if you had `Maybe("a string")`, the `toString` output would be `'Maybe(a string)'`; it is now `'Maybe("a string")'`. Fixes #330
TS 4.7 catches a class of error which 4.6 and earlier did not, courtesy of microsoft/TypeScript#43183: if the type passed does not implement `toString()`, it notices, because it no longer defaults to falling back to `{}`. To resolve this, *loosen* the constraints on what is acceptable as input to `toString`, by making the implementation itself more robust. Doing so also fixes a bug with the output for `toString` when working with strings: previously if you had `Maybe("a string")`, the `toString` output would be `'Maybe(a string)'`; it is now `'Maybe("a string")'`. Fixes #330
(cherry picked from commit 25adb1a) --- Original message: Add support for TypeScript 4.7 TS 4.7 catches a class of error which 4.6 and earlier did not, courtesy of microsoft/TypeScript#43183: if the type passed does not implement `toString()`, it notices, because it no longer defaults to falling back to `{}`. To resolve this, *loosen* the constraints on what is acceptable as input to `toString`, by making the implementation itself more robust. Doing so also fixes a bug with the output for `toString` when working with strings: previously if you had `Maybe("a string")`, the `toString` output would be `'Maybe(a string)'`; it is now `'Maybe("a string")'`. Fixes #330
| Back | FazBrowse Home | New Git URL |
In #15576 we improved control flow analysis for references of generic types with nullable constraints when those references occur in constraint positions (locations where it is known we'll fetch the constraint).
This PR expands the concept further. Specifically, when the type of a reference is or contains a generic type with a union type constraint, and when the reference is in a constraint position or has a contextual type containing no generic types (meaning constraints will determine assignability), we substitute constraints for all generic types in the type of the reference to give control flow analysis an opportunity to narrow it further. For example:
Above, in x.length we substitute string | undefined for T in the type of x because x occurs in a constraint position. Similarly in return x we substitute string | undefined for T in the type of x because x has the contextual type string (due to the return type annotation on the containing function) which contains no generic types. Following substitution, control flow analysis is then able to narrow string | undefined to string based on the truthiness check in the containing if statement.
Some additional examples:
Fixes #13995.
Fixes #20375.
Fixes #42939.