Closed
Description
Bug Report
π Search Terms
recursive type constraint
π Version & Regression Information
- This changed between versions 4.9 and 5.0 Beta
β― Playground Link
Only happens in multi files projects in VS Code. Repo: https://github.com/dragomirtitian/recursive-type-constarint-bug-ts-5.0
π» Code
/// types.ts
export type<T extends Record<string, (...params: unknown[]) => unknown>> = {
[key in keyof T]: T[key];
};
/// index.ts
export declare const value2: {
sliceSelectors: <FuncMap extends import('./types').SelectorMap<FuncMap>>(selectorsBySlice: FuncMap) => { [P in keyof FuncMap]: Parameters<FuncMap[P]> };
};
π Actual behavior
When you first open the project in VS code you get the errors below. Any further editing of the file makes the error s go away.
Type parameter 'FuncMap' has a circular constraint.
Type 'FuncMap[P]' does not satisfy the constraint '(...args: any) => any'.
Type 'FuncMap[keyof FuncMap]' is not assignable to type '(...args: any) => any'.
Type 'FuncMap[string] | FuncMap[number] | FuncMap[symbol]' is not assignable to type '(...args: any) => any'.
Type 'FuncMap[string]' is not assignable to type '(...args: any) => any'.
Also happens in a custom build tool using the compiler API
π Expected behavior
The code either fails all the time or type checks all the time
Note: The circular constraint which is present above and seems to trigger the bug doesnβt seem to make much sense in our case, so we took the opportunity to clean up the types, so this is not blocking for us, but the behavior is still very strange.
Activity
RyanCavanaugh commentedon Feb 3, 2023
Would you be able to bisect this?
dragomirtitian commentedon Feb 3, 2023
@RyanCavanaugh First comit to error seems to be aa2781d From this PR #51766
The changes in the comit are a plausible cause. They impact type constraint checking, they are for a bug that manifests across files. The added diagnostic is lazy, which might explain some of the now you see it now you don't quality of the bug.
DanielRosenwasser commentedon Feb 14, 2023
Should the code be declared as
?
jakebailey commentedon Feb 21, 2023
I sent #52861 to fix this; I think this is the last of the issues reported on #52670, correct?
dragomirtitian commentedon Feb 22, 2023
@jakebailey yup, is the last one. Thank you for the quick turn around :)