eclipse / n4js

Eclipse Public License 1.0
30 stars 27 forks source link

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

Closed mmews-n4 closed 9 months ago

mmews-n4 commented 9 months ago

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.