Closed samreid closed 2 months ago
I believe we can fix the type error in Concat with a conditional type check, like so:
Subject: [PATCH] Round to nearest thousandth, see https://github.com/phetsims/projectile-data-lab/issues/265
---
Index: js/types/Concat.ts
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/types/Concat.ts b/js/types/Concat.ts
--- a/js/types/Concat.ts (revision dcab3dec9107be23c3599468a095d34680c37640)
+++ b/js/types/Concat.ts (date 1712241704251)
@@ -11,5 +11,5 @@
* @author Jonathan Olson <jonathan.olson@colorado.edu>
*/
-type Concat<T> = T extends [ infer A, ...infer Rest ] ? A extends IntentionalAny[] ? [ ...A, ...Concat<Rest> ] : A : T;
+type Concat<T> = T extends [ infer A, ...infer Rest ] ? A extends IntentionalAny[] ? [ ...A, ...( Concat<Rest> extends IntentionalAny[] ? Concat<Rest> : [] ) ] : A : T;
export default Concat;
\ No newline at end of file
Please note that Concat was added in Feb 2022 and has 0 usages across our project at the moment.
The lint changes are all from typescript's improved type inference ability. For example, the first case is WebGPURecorder.ts:
Object.keys( value ).forEach( key => {
if ( objectOverrides && objectOverrides[ key ] ) {
map[ key ] = objectOverrides[ key ]!( value[ key ] );
}
The type assertion is no longer necessary since typescript knows objectOverrides[key] exists from the previous line.
Likewise, the first error in Circuit Construction Kit:
update = () => {
readoutValueNode!.visible = showValuesProperty.value && circuitElement.isValueDisplayableProperty.value;
It now knows that readoutValueNode
is narrowed to Node
so the type assertion is no longer needed there.
There are all good reasons to move to TypeScript 5.4.
@zepumph and I committed this, and it seems good. Closing.
I was very happy to see the changes that this new version brought. Type checking definitely got smarting. Thanks TypeScript!
Typescript 5.4 was released about a month ago: https://devblogs.microsoft.com/typescript/announcing-typescript-5-4/
It has some improved narrowing, and updated types that will be helpful for our project. To update TypeScript, we would also need to update ESLint + typescript-eslint.
Here is a patch with current versions for these releases:
With these new versions, tsc/all has one new type error:
And lint-everything has ✖ 52 problems (51 errors, 1 warning):