Skip to content

Commit

Permalink
fix generics for JavaScript + subclassing
Browse files Browse the repository at this point in the history
  • Loading branch information
inferrinizzard committed Apr 6, 2024
1 parent 8d7c622 commit 4acad79
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
14 changes: 11 additions & 3 deletions packages/quicktype-core/src/language/JavaScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DisplayName, Names, Extension> {
constructor(
displayName = "JavaScript" as DisplayName,
names = ["javascript", "js", "jsx"] as unknown as Names,
extension = "js" as Extension
) {
super(displayName, names, extension);
}

protected getOptions(): Option<any>[] {
Expand Down
18 changes: 15 additions & 3 deletions packages/quicktype-core/src/language/TypeScriptFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<DisplayName, Names, Extension> {
protected constructor(displayName: DisplayName, names: Names, extension: Extension) {
super(displayName, names, extension);
}

protected getOptions(): Option<any>[] {
return [
tsFlowOptions.justTypes,
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down

0 comments on commit 4acad79

Please sign in to comment.