Bad generated type in class auto-implemented member (Typescript)
Hello,
I have a problem with the way webstorm implements class methods based on a type witch contains a template literal. This behavior happens when implementing an interface in a class or implementing members in an object. Here is an example:
what happens :
export class Aclass implements ControllerGenerator<'classmodel'> {
connect<K>(body: Api.BodyT<`/api/${"projects"}/${"connect"}`>): Promise<Api.Returned<`/api/${"projects"}/${"connect"}`>> | Api.Returned<`/api/${"projects"}/${"connect"}`> {
return undefined;
}
}
what is the wanted output :
export class Aclass implements ControllerGenerator<'classmodel'> {
connect(body: Api.BodyT<`/api/projects/connect`>): Promise<Api.Returned<`/api/projects/connect`>> | Api.Returned<`/api/projects/connect`> {
return undefined;
}
}
here is the type definition :
export type ClassGenerator<T extends AllControllers> = {
[K in Endpoints<T>]: (body: BodyT<`/api/${T}/${K}`>, req: { user: { userUid: string } }) => Promise<Returned<`/api/${T}/${K}`>> | Returned<`/api/${T}/${K}`>
}
export type FormatRoute<T> = T extends `${infer A}/${infer B}` ?
(T extends `${infer C}/:${infer D}` ?
`${Lowercase<C>}${Capitalize<D>}` : `${A}_${B}`) : T extends `${infer Total}` ?
Total : never;
export type FormatGenerator<T> = {
[K in keyof T as FormatRoute<K>]: T[K]
}
export type ControllerGenerator<T extends AllControllers> = FormatGenerator<ClassGenerator<T>>;
Please sign in to leave a comment.
Please could you share the self-contained, full code snippets? What does AllControllers definition look like, etc.? ts files would be helpful
you will find the complete example at: https://github.com/chmartin-git/example-typescript-webstorm
Thank you:) Please vote for https://youtrack.jetbrains.com/issue/WEB-50349 to be notified on any progress with it
Thank you !