diff --git a/packages/quicktype-core/src/language/JavaScript.ts b/packages/quicktype-core/src/language/JavaScript.ts index 12a18e320..304a6c775 100644 --- a/packages/quicktype-core/src/language/JavaScript.ts +++ b/packages/quicktype-core/src/language/JavaScript.ts @@ -65,9 +65,17 @@ export type JavaScriptTypeAnnotations = { never: string; }; -export class JavaScriptTargetLanguage extends TargetLanguage<"JavaScript", ["javascript", "js", "jsx"], "js"> { - constructor() { - super("JavaScript", ["javascript", "js", "jsx"], "js"); +export class JavaScriptTargetLanguage< + DisplayName extends string = "JavaScript", + Names extends readonly string[] = readonly ["javascript", "js", "jsx"], + Extension extends string = "js" +> extends TargetLanguage { + constructor( + displayName = "JavaScript" as DisplayName, + names = ["javascript", "js", "jsx"] as unknown as Names, + extension = "js" as Extension + ) { + super(displayName, names, extension); } protected getOptions(): Option[] { diff --git a/packages/quicktype-core/src/language/TypeScriptFlow.ts b/packages/quicktype-core/src/language/TypeScriptFlow.ts index f21202056..664ff92d2 100644 --- a/packages/quicktype-core/src/language/TypeScriptFlow.ts +++ b/packages/quicktype-core/src/language/TypeScriptFlow.ts @@ -40,7 +40,15 @@ const tsFlowTypeAnnotations = { boolean: ": boolean" }; -export abstract class TypeScriptFlowBaseTargetLanguage extends JavaScriptTargetLanguage { +export abstract class TypeScriptFlowBaseTargetLanguage< + DisplayName extends string, + Names extends readonly string[], + Extension extends string +> extends JavaScriptTargetLanguage { + protected constructor(displayName: DisplayName, names: Names, extension: Extension) { + super(displayName, names, extension); + } + protected getOptions(): Option[] { return [ tsFlowOptions.justTypes, @@ -68,7 +76,11 @@ export abstract class TypeScriptFlowBaseTargetLanguage extends JavaScriptTargetL ): JavaScriptRenderer; } -export class TypeScriptTargetLanguage extends TypeScriptFlowBaseTargetLanguage { +export class TypeScriptTargetLanguage extends TypeScriptFlowBaseTargetLanguage< + "TypeScript", + ["typescript", "ts", "tsx"], + "ts" +> { constructor() { super("TypeScript", ["typescript", "ts", "tsx"], "ts"); } @@ -339,7 +351,7 @@ export class TypeScriptRenderer extends TypeScriptFlowBaseRenderer { } } -export class FlowTargetLanguage extends TypeScriptFlowBaseTargetLanguage { +export class FlowTargetLanguage extends TypeScriptFlowBaseTargetLanguage<"Flow", ["flow"], "js"> { constructor() { super("Flow", ["flow"], "js"); }