Skip to content

Recursive type constraint sometimes causes type checking errors. #52570

Closed
@dragomirtitian

Description

@dragomirtitian

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

RyanCavanaugh commented on Feb 3, 2023

@RyanCavanaugh
Member

Also happens in a custom build tool using the compiler API

Would you be able to bisect this?

dragomirtitian

dragomirtitian commented on Feb 3, 2023

@dragomirtitian
ContributorAuthor

@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.

added this to the Backlog milestone on Feb 3, 2023
DanielRosenwasser

DanielRosenwasser commented on Feb 14, 2023

@DanielRosenwasser
Member

Should the code be declared as

export type SelectorMap

?

jakebailey

jakebailey commented on Feb 21, 2023

@jakebailey
Member

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

dragomirtitian

dragomirtitian commented on Feb 22, 2023

@dragomirtitian
ContributorAuthor

@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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Participants

      @DanielRosenwasser@jakebailey@RyanCavanaugh@dragomirtitian

      Issue actions

        Recursive type constraint sometimes causes type checking errors. Β· Issue #52570 Β· microsoft/TypeScript