Uh oh!
There was an error while loading. Please reload this page.
Remove assignability cases in getNarrowedType + an isArray improvement for readonly arrays - #39258
Conversation
Ryan Cavanaugh (RyanCavanaugh)
commented
Jun 25, 2020
TypeScript Bot (@typescript-bot) test this |
Heya Ryan Cavanaugh (@RyanCavanaugh), I've started to run the parallelized community code test suite on this PR at 855fd84. You can monitor the build here. |
Heya Ryan Cavanaugh (@RyanCavanaugh), I've started to run the extended test suite on this PR at 855fd84. You can monitor the build here. |
TypeScript Bot (typescript-bot)
commented
Jun 25, 2020
The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master. |
Ryan Cavanaugh (RyanCavanaugh)
commented
Jun 25, 2020
TypeScript Bot (@typescript-bot) test this |
Heya Ryan Cavanaugh (@RyanCavanaugh), I've started to run the parallelized community code test suite on this PR at ed01085. You can monitor the build here. |
Heya Ryan Cavanaugh (@RyanCavanaugh), I've started to run the extended test suite on this PR at ed01085. You can monitor the build here. |
Ryan Cavanaugh (RyanCavanaugh)
left a comment
There was a problem hiding this comment.
I don't think this is going to work. See https://mseng.visualstudio.com/Typescript/_git/Typescript/pullrequest/560730?_a=files for RWC breaks
Seems to be tripping up when the guarded value has type declarefunctionisArray<T>(arg: T|{}): arg is Textendsreadonly(infer U)[] ? GroundArray<T,U>: any[];typeGroundArray<Textendsreadonlyunknown[],U>=[T]extends[U[]] ? any[] : T; |
Wesley Wigham (weswigham)
commented
Jul 1, 2020
isArray<T>(arg: T|{}): arg is Textendsreadonlyany[] ? (unknownextendsT ? never : readonlyany[]) : any[];should also work to filter out |
Orta Therox (orta)
commented
Jul 8, 2020
TypeScript Bot (@typescript-bot) test this |
Heya Orta Therox (@orta), I've started to run the parallelized community code test suite on this PR at c69b255. You can monitor the build here. |
Heya Orta Therox (@orta), I've started to run the extended test suite on this PR at c69b255. You can monitor the build here. |
Orta Therox (orta)
commented
Jul 13, 2020
OK, so that does clean up most of the errors in the RWC in the azure side - it looks like just a few rxjs issues and they all stem to their own custom exportconstisArray=(()=>Array.isArray||(<T>(x: any): x is T[]=>x&&typeofx.length==='number'))();We're still seeing issues in this PR: typescript-bot#53 this could be because they have their own exportfunctionisArray(array: any): array is any[]{returnArray.isArray(array);}I could update the vscode definition to the new definition to see if that fixes it |
Wesley Wigham (weswigham)
commented
Jul 13, 2020
Yeah, the custom |
Orta Therox (orta)
commented
Jul 13, 2020
Looks like I need a build to verify rxjs TypeScript Bot (@typescript-bot) pack this |
Heya Orta Therox (@orta), I've started to run the tarball bundle task on this PR at c69b255. You can monitor the build here. |
Hey Orta Therox (@orta), I've packed this into an installable tgz. You can install it for testing by referencing it in your and then running There is also a playground for this build. |
Orta Therox (orta)
commented
Jul 30, 2020
TypeScript Bot (@typescript-bot) pack this |
Orta Therox (orta)
commented
Sep 3, 2020
I'll merge on tuesday when I'm off DT rotation 👍🏻 |
Orta Therox (orta)
commented
Sep 8, 2020
Today is that tuesday, I'm going to merge 👍🏻 |
Typescript 4.1 will have [stricter rules for type predicates](microsoft/TypeScript#39258) like ```ts export const isObject = (val: unknown): val is Record<any, any> => val !== null && typeof val === 'object' ``` As a result of these rules, an expression in collectionHandlers.ts in the reactivity package doesn't get narrowed to the type it did in TS 4.0 and below. Instead it gets an intersection type, which doesn't work with subsequent code. I restored the old type using a cast, since that's essentially what the old version of Typescript was doing here.
Ryan Cavanaugh (RyanCavanaugh)
commented
Oct 19, 2020
Example for blog post declareconstp: string|ReadonlyArray<string>;if(Array.isArray(p)){// 4.0: p: any[]// 4.1: p: readonly string[];// 4.0: OK// 4.1: Errorp.push(0);} |
Han Seoul-Oh (laughinghan)
commented
Nov 2, 2020
FWIW, possibly a better example for the blogpost is one where TypeScript narrowed the type incorrectly and unsafely, rather than merely providing a weaker-than-desired type, e.g.: declarevarfoo: string[]|readonlynumber[]|nullif(fooinstanceofArray){foo;// at runtime, this may be string[] or readonly number[],// however, TypeScript <4.1 would narrow to just string[]foo.push('str');// incorrect and unsafe, but allowed by <4.1, now errors in Nightly}else{foo;// at runtime, strictly null, however TypeScript <4.1 would// narrow to readonly number[] | null} |
Felix Becker (felixfbecker)
commented
Nov 20, 2020
Orta Therox (@orta) I think this broke passing |
Victor Garcia (victorgarciaesgi)
commented
Nov 20, 2020
It brokes a lot de |
Orta Therox (@orta) / Ryan Cavanaugh (@RyanCavanaugh) This PR has the https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#typescript-41 |
Yudhi Seymour (yseymour)
commented
Nov 20, 2020
This is broken for generics and other nontrivial types: declarefunctionf1<Textendsany[]>(array: T): void;functionf2<T>(thing: T){if(Array.isArray(thing)){f1(thing);// Argument of type 'T & (T extends readonly any[] ? unknown extends T ? never : readonly any[] : any[])' is not assignable to parameter of type 'any[]'.}}In 4.0, the type of |
Martin Johns (MartinJohns)
commented
Nov 28, 2020
Another issue caused by the improvement: #41714 |
Fixes#31155
Fixes#17002
There are two pieces to this PR:
The 2nd was blocked on :
Where :
Is now legal due to changes in the
isArraydefinition which takes into accountreadonlyarrays./cc Jack Williams (@jack-williams)