samchon / tgrid

TypeScript RPC (Remote Procedure Call) for WebSocket and Worker protocols
https://tgrid.com/
MIT License
146 stars 19 forks source link

Error in the 'Driver.d.ts' file: duplicated identifier #26

Closed samchon closed 4 years ago

samchon commented 5 years ago

Summary

Implementing the https://github.com/samchon/tgrid/issues/24, an ambiguous error has been occuring. There's not any error in the Driver.ts file, but its output file Driver.d.ts reports an error: Duplicated identifier Driver.

Such error occurs when a namespace, designed only for type definition, shares same name with a variable and some of type definitions in the namespace are exported and some of them are not expored. If all of the definitions in the namespace are exported, there wouldn't be any error.

It seems a bug of the TypeScript compiler. So I've published an issue reporting the bug: https://github.com/microsoft/TypeScript/issues/34896

Code occuring the bug

src/components/Driver.ts

components/Driver.d.ts

export declare type Driver<Controller extends object, Parametric extends boolean = false> = Driver.Promisive<Controller, Parametric>;
export declare var Driver: {
    new (): {};
};
export declare namespace Driver {
    export type Promisive<Instance extends object, UseParametric extends boolean = false> = {
        readonly [P in keyof Instance]: Instance[P] extends Function ? Functional<Instance[P], UseParametric> : value_of<Instance[P]> extends object ? Instance[P] extends object ? Promisive<Instance[P], UseParametric> : never : never;
    } & IRemoteObject;
    export type Functional<Method extends Function, UseParametric extends boolean = false> = (Method extends (...args: infer Params) => infer Ret ? Ret extends Promise<infer PromiseRet> ? (...args: FunctionalParams<Params, UseParametric>) => Promise<Primitive<PromiseRet>> : (...args: FunctionalParams<Params, UseParametric>) => Promise<Primitive<Ret>> : (...args: any[]) => Promise<any>) & IRemoteFunction;
    type FunctionalParams<Params extends any[], UseParametric extends boolean> = UseParametric extends true ? Parametric<Params> : Params;
    export type Primitive<Instance> = value_of<Instance> extends object ? Instance extends object ? Instance extends IJsonable<infer Raw> ? value_of<Raw> extends object ? Raw extends object ? PrimitiveObject<Raw> : never : value_of<Raw> : PrimitiveObject<Instance> : never : value_of<Instance>;
    type PrimitiveObject<Instance extends object> = {
        [P in keyof Instance]: Instance[P] extends Function ? never : Primitive<Instance[P]>;
    };
    export type Parametric<Arguments extends any[]> = {
        [P in keyof Arguments]: ParametricValue<Arguments[P]>;
    };
    type ParametricValue<Instance> = value_of<Instance> | Primitive<Instance> | IJsonable<Primitive<Instance>>;
    type value_of<Instance> = is_value_of<Instance, Boolean> extends true ? boolean : is_value_of<Instance, Number> extends true ? number : is_value_of<Instance, String> extends true ? string : Instance;
    type is_value_of<Instance, Object extends IValueOf<any>> = Instance extends Object ? Object extends IValueOf<infer Primitive> ? Instance extends Primitive ? false : true : false : false;
    interface IRemoteObject {
        constructor: never;
        prototype: never;
    }
    type IRemoteFunction = {
        [P in keyof Function | "Symbol"]: never;
    };
    interface IValueOf<T> {
        valueOf(): T;
    }
    export {};
}
samchon commented 5 years ago

Until the TypeScript fixes the bug, it would better to export all of the type definitions in the namespace Driver.