Skip to content

Recursive type constraint sometimes causes type checking errors. #52570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dragomirtitian opened this issue Feb 2, 2023 · 5 comments Β· Fixed by #52861
Closed

Recursive type constraint sometimes causes type checking errors. #52570

dragomirtitian opened this issue Feb 2, 2023 · 5 comments Β· Fixed by #52861
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this
Milestone

Comments

@dragomirtitian
Copy link
Contributor

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.

@RyanCavanaugh
Copy link
Member

Also happens in a custom build tool using the compiler API

Would you be able to bisect this?

@dragomirtitian
Copy link
Contributor Author

dragomirtitian commented 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.

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Feb 3, 2023
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Feb 3, 2023
@RyanCavanaugh RyanCavanaugh added the Help Wanted You can do this label Feb 3, 2023
@DanielRosenwasser
Copy link
Member

Should the code be declared as

export type SelectorMap

?

@jakebailey
Copy link
Member

I sent #52861 to fix this; I think this is the last of the issues reported on #52670, correct?

@dragomirtitian
Copy link
Contributor Author

@jakebailey yup, is the last one. Thank you for the quick turn around :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants