Skip to content

TypeScript's meta type language has issues with circular type structures #2576

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
mmews-n4 opened this issue Nov 21, 2023 · 0 comments · Fixed by #2578
Closed

TypeScript's meta type language has issues with circular type structures #2576

mmews-n4 opened this issue Nov 21, 2023 · 0 comments · Fixed by #2578
Assignees

Comments

@mmews-n4
Copy link

mmews-n4 commented Nov 21, 2023

In case a type T has a field also of type T (circular reference), TypeScripts meta type language features cause issues:

Example of problematic TypeScript type

export interface Clash {
    someMethod():void;
    fieldWithError: ExcludeMethods<Clash>[]; // 2 errors here, second is of interest
    // Error 0: 'fieldWithError' is referenced directly or indirectly in its own type annotation.
    // Error 1: Type of property 'fieldWithError' circularly references itself in mapped type '{ [K in keyof Clash]: Clash[K] extends Function ? never : K; }'
}

type ExcludeMethods<T> = Pick<T, { [K in keyof T]: T[K] extends Function ? never : K }[keyof T]>;

Since we use this definition when transpiling from n4js to d.ts, there can be errors in the resulting d.ts output. This needs to be addressed.

@mmews-n4 mmews-n4 self-assigned this Nov 21, 2023
mmews-n4 pushed a commit that referenced this issue Nov 23, 2023
…e structures (#2578)

* add test

* improve test

* fix

* improve test

* use newer version of TypeScript

* fix

* improve test

* fix

* improve tests

* fix

* more fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant