You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
error TS5056: Cannot write file '/mnt/ts_downloads/chakra-ui/packages/components/dist/types/menu/menu.stories.d.ts' because it would be overwritten by multiple input files.
error TS2345: Argument of type 'SQLiteD1Session<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.
error TS2345: Argument of type 'LibSQLSession<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.
error TS2536: Type 'keyof TSchema' cannot be used to index type 'TFullSchema extends Record<string, never> ? DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> : { [K in keyof TSchema]: RelationalQueryBuilder<TResultKind, TFullSchema, TSchema, TSchema[K]>; }'.
error TS2345: Argument of type 'SQLiteD1Session<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.
error TS2345: Argument of type 'LibSQLSession<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.
error TS2536: Type 'keyof TSchema' cannot be used to index type 'TFullSchema extends Record<string, never> ? DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> : { [K in keyof TSchema]: RelationalQueryBuilder<TResultKind, TFullSchema, TSchema, TSchema[K]>; }'.
error TS2345: Argument of type 'SQLiteD1Session<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.
error TS2345: Argument of type 'LibSQLSession<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.
error TS2536: Type 'keyof TSchema' cannot be used to index type 'TFullSchema extends Record<string, never> ? DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> : { [K in keyof TSchema]: RelationalQueryBuilder<TResultKind, TFullSchema, TSchema, TSchema[K]>; }'.
error TS2345: Argument of type 'SQLiteD1Session<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.
error TS2345: Argument of type 'LibSQLSession<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.
error TS2536: Type 'keyof TSchema' cannot be used to index type 'TFullSchema extends Record<string, never> ? DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> : { [K in keyof TSchema]: RelationalQueryBuilder<TResultKind, TFullSchema, TSchema, TSchema[K]>; }'.
error TS1292: 'Quill' resolves to a type and must be marked type-only in this file before re-exporting when 'verbatimModuleSyntax' is enabled. Consider using 'export type { Quill as default }'.
error TS2742: The inferred type of 'resolveParserPlugins' cannot be named without a reference to 'packages/compiler-core/node_modules/@babel/parser/typings/babel-parser'. This is likely not portable. A type annotation is necessary.
That was just a typo - I meant what you have confirmed 😉 That minimal repro didn't typecheck with 5.3 so it just continues to be an error with the current nightly of 5.4 and because of that it's unlikely to be related to any errors reported here.
I double checked qwik. The errors below are definitely caused by #56598. I manually reverted that PR's checker diff and the errors went away. I'll try to make a small repro.
error TS2345: Argument of type 'EventQRL<T>' is not assignable to parameter of type 'EventQRL<"copy" | "progress" | "reset" | "scroll" | "resize" | "drag" | "fullscreenchange" | "fullscreenerror" | "abort" | "animationcancel" | "animationend" | "animationiteration" | ... 112 more ... | "qvisible">'.
Regarding the new react-hook-form error, the issue is the Record<string, any> constraint on T. We have rule that says an object with an [x: string]: any index signature is a supertype of any object type, even if that object type doesn't have a matching index signature. This includes function types, so in the example, the typeof options === "function" check can't just narrow the type to AsyncDefaultValues<T>. Indeed, options could be any arbitrary function. To wit, this call is permitted:
f(()=>"hello");
The reason we issue an implicit any error on the data parameter is that, since the function check can really only narrow to type Function, we end up with an untyped function call.
Things work fine when the constraint of T is changed to Record<string, unknown>. In that case we error on calls to f with arbitrary function types, and we narrow to AsyncDefaultValues<T> following the function check.
Other than adding a type assertion, I'm not sure what the best fix is in the react-hook-form project since new errors pop up if I just change the constraint to Record<string, unknown>. But, certainly, I think our is correct and points out a latent issue in the code.
Here's an independent repro for qwik's use-on errors. This one fails after #56598 and passes before (where 'before' includes #56004 -- though both are required for the error to appear.)
(I'll have a much smaller repro soon; this is just the first one that is independent of qwik)
exporttypeQ<TYPE=unknown>={// Special type brand to let eslint that the Type is serializable__qwik_serializable__?: any;__brand__Q__: TYPE;/** Resolve the Q and return the actual value. */resolve(): Promise<TYPE>;/** The resolved value, once `resolve()` returns. */resolved: undefined|TYPE;getCaptured(): unknown[]|null;getSymbol(): string;getHash(): string;}typeHandler<EV=Event,EL={}>={bivarianceHack(event: EV,element: EL): any;}['bivarianceHack'];typeVirtualKeys=keyofWMapinterfaceE{}interfaceWMap{"boo": E;}typeAllEventsMap=WMaptypeLcEvent<Textendsstring,Cextendsstring=Lowercase<T>>=CextendskeyofAllEventsMap
? AllEventsMap[C]
: Event;typeVirtualEvent<Textendsstring=VirtualKeys>=|Q<Handler<LcEvent<T>,{}>>|undefined;typeStringy<LiteralType,BaseTypeextendsnull|undefined|string|number|boolean|symbol|bigint>=|LiteralType|(BaseType&Record<never,never>);typeVirtualEventNames=Stringy<VirtualKeys,string>;// VirtualKeys | (string & { });declareconst_virtualOn: (eventQrl: VirtualEvent<VirtualKeys>)=>void;exportconstvirtualOn=<TextendsVirtualEventNames>(eventQrl: VirtualEvent<T>)=>{_virtualOn(eventQrl);// error here where none was before};
Smaller:
// interesting things:// 1. only errors if event in EMap is all lowercase.// 2. bivariance hack is required// 3. Lowercase<T> is requiredtypeEMap={event: {}}typeKeys=keyofEMaptypeEPlusFallback<C>=CextendsKeys
? EMap[C]
: "unrecognised event";typeVirtualEvent<Textendsstring>={bivarianceHack(event: EPlusFallback<Lowercase<T>>): any;}['bivarianceHack'];typeKeysPlusString=Keys|(string&Record<never,never>);declareconst_virtualOn: (eventQrl: VirtualEvent<Keys>)=>void;exportconstvirtualOn=<TextendsKeysPlusString>(eventQrl: VirtualEvent<T>)=>{_virtualOn(eventQrl);};
The error seems to show that the conditional type EPlusFallback isn't assignable to its base contraint:
Argument of type '(event: EPlusFallback<Lowercase<T>>) => any' is not assignable to parameter of type '(event: {}) => any'.
Types of parameters 'event' and 'event' are incompatible.
Type '{}' is not assignable to type 'EPlusFallback<Lowercase<T>>'.ts(2345)
EPlusFallback<Lowercase<T>> should have the base constraint {} | "unrecognised event", but I guess that assignability doesn't try that.
Also: I guess assignability to Lowercase<T> must go through isValidTypeForTemplateLiteralPlaceholder, because that's the only thing that looks relevant to #56598.
Nathan Shively-Sanders (@sandersn) I tried reverting #56598 and it doesn't seem to have any effect. Your repro still errors in the same way. So I think the issue is just caused by #56004.
It repros for me, so maybe it's the tsconfig I'm using. I'll create a standalone repo.
Example run of before/after showing no error/error
✔ ~/ts [main|⚑ 1]
14:30 $ git checkout e5513254a3
Note: switching to 'e5513254a3'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at e5513254a3 Fixed symbol lookup for binding expando properties in blocks (#56552)
✔ ~/ts [:e5513254a3|⚑ 1]
14:31 $ b
Using ~/ts/Herebyfile.mjs to run tsc
Starting lib
Starting generate-diagnostics
> /home/nathansa/.nvm/versions/node/v20.11.0/bin/node scripts/processDiagnosticMessages.mjs src/compiler/diagnosticMessages.json
Reading diagnostics from src/compiler/diagnosticMessages.json
Finished lib in 33ms
Finished generate-diagnostics in 63ms
Starting bundle-tsc
Finished bundle-tsc in 179ms
Completed tsc in 242ms
✔ ~/ts [:e5513254a3|⚑ 1]
14:31 $ pushd
~/src/test ~/ts
t✔ ~/src/test [master L|✚ 15…16]
14:31 $ tsl
✔ ~/src/test [master L|✚ 15…16]
14:31 $ pushd
~/ts ~/src/test
✔ ~/ts [:e5513254a3|⚑ 1]
14:31 $ git checkout 68b9b07
Previous HEAD position was e5513254a3 Fixed symbol lookup for binding expando properties in blocks (#56552)
HEAD is now at 68b9b07264 Consistently check assignability to template literal placeholders (#56598)
✔ ~/ts [:68b9b07264|⚑ 1]
14:31 $ b
Using ~/ts/Herebyfile.mjs to run tsc
Starting lib
Starting generate-diagnostics
> /home/nathansa/.nvm/versions/node/v20.11.0/bin/node scripts/processDiagnosticMessages.mjs src/compiler/diagnosticMessages.json
Reading diagnostics from src/compiler/diagnosticMessages.json
Finished lib in 32ms
Finished generate-diagnostics in 61ms
Starting bundle-tsc
puFinished bundle-tsc in 190ms
Completed tsc in 252ms
s✔ ~/ts [:68b9b07264|⚑ 1]
14:31 $ pushd
~/src/test ~/ts
✔ ~/src/test [master L|✚ 15…16]
14:31 $ tsl
welove.ts:22:14 - error TS2345: Argument of type '(event: EPlusFallback<Lowercase<T>>) => any' is not assignable to parameter of type '(event: {}) => any'.
Types of parameters 'event' and 'event' are incompatible.
Type '{}' is not assignable to type 'EPlusFallback<Lowercase<T>>'.
22 _virtualOn(eventQrl);
~~~~~~~~
Found 1 error in welove.ts:22
✘-2 ~/src/test [master L|✚ 15…16]
Ok, I see the same effects with your repro. The root cause is #56004, but the issue only shows up after #56598 because that PR fixes template literal placeholder matching such that `${string & Record<never, never>}` behaves the same as just `${string}` (which indeed it should). And apparently we use template literal matching when checking relations for two string mapping types (this happens in isMemberOfStringMapping). Crazy.
The repro checks whether EPlusFallback<Lowercase<T>> is assignable to EPlusFallback<Keys> (which is just {}).
With #56004, the constraint of EPlusFallback<Lowercase<T>> ends up correctly being type EMap["event" & Lowercase<T>] | "unrecognized event", where previously it would just be "unrecognized event".
The constraint of EMap["event" & Lowercase<T>] in turn is reduced to EMap["event" & Lowercase<string>].
This is where things go wrong. We currently lack the ability to reduce unions and intersections of string literal types (like "event") and string mapping types with non-generic placeholders (like Lowercase<string>). The intersection "event" & Lowercase<string> really should reduce to just "event", but it doesn't. So, we fail to consider it a valid index type in EMap["event" & Lowercase<string>], which therefore ends up being unknown. And unknown isn't assignable to {}, so therefore error.
So, long story short, we can fix this issue by doing a better job reducing unions and intersections of string literal types and string mapping types with non-generic placeholders. I will look at putting up a PR.
Activity
typescript-bot commentedon Jan 21, 2024
BuilderIO/qwik
10 of 11 projects failed to build with the old tsc and were ignored
tsconfig.json
error TS2604: JSX element type 'Cmp' does not have any construct or call signatures.error TS2345: Argument of type 'EventQRL<T>' is not assignable to parameter of type 'EventQRL<"copy" | "progress" | "reset" | "scroll" | "resize" | "drag" | "fullscreenchange" | "fullscreenerror" | "abort" | "animationcancel" | "animationend" | "animationiteration" | ... 112 more ... | "qvisible">'.typescript-bot commentedon Jan 21, 2024
chakra-ui/chakra-ui
4 of 28 projects failed to build with the old tsc and were ignored
packages/components/tsconfig.build.json
error TS5056: Cannot write file '/mnt/ts_downloads/chakra-ui/packages/components/dist/types/menu/menu.stories.d.ts' because it would be overwritten by multiple input files.typescript-bot commentedon Jan 21, 2024
drizzle-team/drizzle-orm
18 of 25 projects failed to build with the old tsc and were ignored
drizzle-orm/tests/tsconfig.json
error TS2345: Argument of type 'SQLiteD1Session<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.error TS2345: Argument of type 'LibSQLSession<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.error TS2536: Type 'keyof TSchema' cannot be used to index type 'TFullSchema extends Record<string, never> ? DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> : { [K in keyof TSchema]: RelationalQueryBuilder<TResultKind, TFullSchema, TSchema, TSchema[K]>; }'.error TS2536: Type 'keyof TSchema' cannot be used to index type 'this["query"]'.drizzle-orm/tsconfig.dts.json
error TS2345: Argument of type 'SQLiteD1Session<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.error TS2345: Argument of type 'LibSQLSession<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.error TS2536: Type 'keyof TSchema' cannot be used to index type 'TFullSchema extends Record<string, never> ? DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> : { [K in keyof TSchema]: RelationalQueryBuilder<TResultKind, TFullSchema, TSchema, TSchema[K]>; }'.error TS2536: Type 'keyof TSchema' cannot be used to index type 'this["query"]'.drizzle-orm/tsconfig.json
error TS2345: Argument of type 'SQLiteD1Session<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.error TS2345: Argument of type 'LibSQLSession<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.error TS2536: Type 'keyof TSchema' cannot be used to index type 'TFullSchema extends Record<string, never> ? DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> : { [K in keyof TSchema]: RelationalQueryBuilder<TResultKind, TFullSchema, TSchema, TSchema[K]>; }'.error TS2536: Type 'keyof TSchema' cannot be used to index type 'this["query"]'.drizzle-orm/type-tests/tsconfig.json
error TS2345: Argument of type 'SQLiteD1Session<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.error TS2345: Argument of type 'LibSQLSession<TSchema, ExtractTablesWithRelations<TSchema>>' is not assignable to parameter of type 'SQLiteSession<"async", unknown, Record<string, unknown>, TablesRelationalConfig>'.error TS2536: Type 'keyof TSchema' cannot be used to index type 'TFullSchema extends Record<string, never> ? DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB type?"> : { [K in keyof TSchema]: RelationalQueryBuilder<TResultKind, TFullSchema, TSchema, TSchema[K]>; }'.error TS2536: Type 'keyof TSchema' cannot be used to index type 'this["query"]'.typescript-bot commentedon Jan 21, 2024
heyxyz/hey
1 of 12 projects failed to build with the old tsc and were ignored
apps/web/tsconfig.json
error TS2865: Import 'PublicationStats' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.typescript-bot commentedon Jan 21, 2024
pixijs/pixijs
tsconfig.json
error TS2430: Interface 'ICanvasRenderingContext2D' incorrectly extends interface 'CanvasTextDrawingStyles'.tsconfig.types.json
error TS2430: Interface 'ICanvasRenderingContext2D' incorrectly extends interface 'CanvasTextDrawingStyles'.typescript-bot commentedon Jan 21, 2024
prisma/prisma
75 of 106 projects failed to build with the old tsc and were ignored
packages/debug/tsconfig.build.json
error TS2865: Import 'Debug' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.packages/debug/tsconfig.json
error TS2865: Import 'Debug' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.packages/get-platform/tsconfig.json
error TS2865: Import 'Debug' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.packages/engines/tsconfig.build.json
error TS2865: Import 'Debug' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.packages/engines/tsconfig.json
error TS2865: Import 'Debug' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.packages/generator-helper/tsconfig.json
error TS2865: Import 'Debug' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.packages/internals/tsconfig.json
error TS2865: Import 'Debug' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.packages/instrumentation/tsconfig.json
error TS2865: Import 'Debug' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.packages/client/tsconfig.build.json
error TS2865: Import 'Debug' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.packages/cli/tsconfig.build.json
error TS2865: Import 'Debug' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled.typescript-bot commentedon Jan 21, 2024
pubkey/rxdb
9 of 11 projects failed to build with the old tsc and were ignored
tsconfig.json
error TS2339: Property 'previousDocumentData' does not exist on type 'EventBulk<RxStorageChangeEvent<TestDocType>, any>'.error TS2339: Property 'operation' does not exist on type 'EventBulk<RxStorageChangeEvent<TestDocType>, any>'.error TS2339: Property 'documentData' does not exist on type 'EventBulk<RxStorageChangeEvent<any>, any>'.typescript-bot commentedon Jan 21, 2024
quilljs/quill
packages/quill/tsconfig.json
error TS2578: Unused '@ts-expect-error' directive.tsconfig.json
error TS1292: 'Quill' resolves to a type and must be marked type-only in this file before re-exporting when 'verbatimModuleSyntax' is enabled. Consider using 'export type { Quill as default }'.error TS2578: Unused '@ts-expect-error' directive.typescript-bot commentedon Jan 21, 2024
react-hook-form/react-hook-form
2 of 3 projects failed to build with the old tsc and were ignored
tsconfig.json
error TS7006: Parameter 'values' implicitly has an 'any' type.typescript-bot commentedon Jan 21, 2024
reduxjs/react-redux
2 of 3 projects failed to build with the old tsc and were ignored
test/typetests/tsconfig.json
error TS2313: Type parameter 'U' has a circular constraint.error TS2578: Unused '@ts-expect-error' directive.typescript-bot commentedon Jan 21, 2024
refined-github/refined-github
tsconfig.json
error TS2344: Type 'ParseSelector<Selector, HTMLElement>' does not satisfy the constraint 'HTMLElement'.error TS2344: Type 'ExpectedElement' does not satisfy the constraint 'Element'.error TS2339: Property 'classList' does not exist on type 'ExpectedElement'.error TS2339: Property 'matches' does not exist on type 'ExpectedElement'.error TS2345: Argument of type 'ObserverListener<ExpectedElement>' is not assignable to parameter of type 'ObserverListener<HTMLElement>'.typescript-bot commentedon Jan 21, 2024
vuejs/core
1 of 3 projects failed to build with the old tsc and were ignored
tsconfig.build.json
error TS2742: The inferred type of 'resolveParserPlugins' cannot be named without a reference to 'packages/compiler-core/node_modules/@babel/parser/typings/babel-parser'. This is likely not portable. A type annotation is necessary.error TS2322: Type 'T | DeepReadonly<UnwrapNestedRefs<T & Record<any, any>>>' is not assignable to type 'T'.tsconfig.json
error TS2322: Type 'T | DeepReadonly<UnwrapNestedRefs<T & Record<any, any>>>' is not assignable to type 'T'.MichaelMitchell-at commentedon Jan 22, 2024
Copying over my comment from #56972
Minimal repro of a "cannot be used as an index type" error:
RyanCavanaugh commentedon Jan 22, 2024
michaelm (@MichaelMitchell-at) fix at #57113
RyanCavanaugh commentedon Jan 23, 2024
react-redux is trying to do the should-be-impossible and prevent function arguments from subtyping with this function
demonstrated here:
and also to prevent
anyfrom bypassing errorsTo the extent they once succeeded, they're now broken by #56515. However, this functionality was never used AFAICT, every call is in the form e.g.
so I don't think this is a blocker for that project in particular.
2 remaining items
Andarist commentedon Jan 23, 2024
That was just a typo - I meant what you have confirmed 😉 That minimal repro didn't typecheck with 5.3 so it just continues to be an error with the current nightly of 5.4 and because of that it's unlikely to be related to any errors reported here.
andrewbranch commentedon Jan 24, 2024
Anders Hejlsberg (@ahejlsberg) react-hook-form repro:
https://www.typescriptlang.org/play?module=1&ts=5.4.0-dev.20240124#code/C4TwDgpgBAggziAdgYwCIQGYEMCuAbYANSzxwjgB4AVAMQEsI8ATY08gPigF4oAKAKChQwWEHgD2WJgH4AXFByIA1onEB3RABp+ASm6cACgCdxAWzpwI1eoxYkycdgG5+-UJCjps+IvfLWGZlYHTi5BKFpAuzY4KAgAD2AIRCZY+CQ0TFwCYP9I21zHcKFpWDUsOiSmAIK-IqEheXygupd+DEVkYDpxRCgMajjE5NSoACUIZHEjarhgIzpEAHNNKCxEEHZ2XnEwbt64eS9s3xjqTgAfWAQUY59C870Ab3C6DD53CHF33f3EWK4gKgAHIOig-sDnsUoL8ev9eDoAHTAAAWyV4vCYWGAWD0XE4WJxOhcQgAvvxyUA
Revert microsoft#54477 but keep the tests
sandersn commentedon Jan 25, 2024
I double checked qwik. The errors below are definitely caused by #56598. I manually reverted that PR's checker diff and the errors went away. I'll try to make a small repro.
ahejlsberg commentedon Jan 25, 2024
Regarding the new react-hook-form error, the issue is the
Record<string, any>constraint onT. We have rule that says an object with an[x: string]: anyindex signature is a supertype of any object type, even if that object type doesn't have a matching index signature. This includes function types, so in the example, thetypeof options === "function"check can't just narrow the type toAsyncDefaultValues<T>. Indeed,optionscould be any arbitrary function. To wit, this call is permitted:The reason we issue an implicit any error on the
dataparameter is that, since the function check can really only narrow to typeFunction, we end up with an untyped function call.Things work fine when the constraint of
Tis changed toRecord<string, unknown>. In that case we error on calls tofwith arbitrary function types, and we narrow toAsyncDefaultValues<T>following the function check.Other than adding a type assertion, I'm not sure what the best fix is in the react-hook-form project since new errors pop up if I just change the constraint to
Record<string, unknown>. But, certainly, I think our is correct and points out a latent issue in the code.sandersn commentedon Jan 25, 2024
Here's an independent repro for qwik's use-on errors. This one fails after #56598 and passes before (where 'before' includes #56004 -- though both are required for the error to appear.)
(I'll have a much smaller repro soon; this is just the first one that is independent of qwik)
Smaller:
sandersn commentedon Jan 25, 2024
The error is the one Ryan Cavanaugh (@RyanCavanaugh) and Anders Hejlsberg (@ahejlsberg) found before--
KeysPlusStringis correctly not assignable toKeysinVIrtualEvent.The error seems to show that the conditional type
EPlusFallbackisn't assignable to its base contraint:EPlusFallback<Lowercase<T>>should have the base constraint{} | "unrecognised event", but I guess that assignability doesn't try that.Also: I guess assignability to
Lowercase<T>must go throughisValidTypeForTemplateLiteralPlaceholder, because that's the only thing that looks relevant to #56598.ahejlsberg commentedon Jan 25, 2024
Nathan Shively-Sanders (@sandersn) I tried reverting #56598 and it doesn't seem to have any effect. Your repro still errors in the same way. So I think the issue is just caused by #56004.
sandersn commentedon Jan 25, 2024
It repros for me, so maybe it's the tsconfig I'm using. I'll create a standalone repo.
Example run of before/after showing no error/error
sandersn commentedon Jan 25, 2024
Here's the standalone repo: https://github.com/sandersn/repro56598
ahejlsberg commentedon Jan 26, 2024
Ok, I see the same effects with your repro. The root cause is #56004, but the issue only shows up after #56598 because that PR fixes template literal placeholder matching such that
`${string & Record<never, never>}`behaves the same as just`${string}`(which indeed it should). And apparently we use template literal matching when checking relations for two string mapping types (this happens inisMemberOfStringMapping). Crazy.ahejlsberg commentedon Jan 26, 2024
Anyway, this means the repro can be reduced to:
ahejlsberg commentedon Jan 26, 2024
Ok, I now see what's going on.
The repro checks whether
EPlusFallback<Lowercase<T>>is assignable toEPlusFallback<Keys>(which is just{}).With #56004, the constraint of
EPlusFallback<Lowercase<T>>ends up correctly being typeEMap["event" & Lowercase<T>] | "unrecognized event", where previously it would just be"unrecognized event".The constraint of
EMap["event" & Lowercase<T>]in turn is reduced toEMap["event" & Lowercase<string>].This is where things go wrong. We currently lack the ability to reduce unions and intersections of string literal types (like
"event") and string mapping types with non-generic placeholders (likeLowercase<string>). The intersection"event" & Lowercase<string>really should reduce to just"event", but it doesn't. So, we fail to consider it a valid index type inEMap["event" & Lowercase<string>], which therefore ends up beingunknown. Andunknownisn't assignable to{}, so therefore error.So, long story short, we can fix this issue by doing a better job reducing unions and intersections of string literal types and string mapping types with non-generic placeholders. I will look at putting up a PR.