If you need to support a language not currently in quicktype, you must implement both a TargetLanguage and a Renderer from the ground up.
1. Define the Language Configuration
Create a configuration object containing:
displayName: The human-readable name.names: An array of names used to identify the language.extension: The common file extension for this language.
2. Define Language Options
Use quicktype-core option classes to define user-configurable flags. Available default classes include:
StringOptionBooleanOptionEnumOption
3. Implement the TargetLanguage
Extend TargetLanguage<typeof config> and implement:
getOptions(): Returns your defined language options.makeRenderer(): Returns an instance of your custom Renderer.
4. Implement the Renderer
Extend ConvenienceRenderer and implement the necessary rendering logic in its methods.
import { TargetLanguage, BooleanOption, RenderContext } from "quicktype-core";
// 1. Language config
const brandNewLanguageConfig = {
displayName: "Scratch",
names: ["scratch"],
extension: "sb"
} as const;
// 2. Language options
const brandNewLanguageOptions = {
allowFoo: new BooleanOption("allow-foo", "Allows Foo", true)
};
// 3. TargetLanguage implementation
class BrandNewLanguage extends TargetLanguage<typeof brandNewLanguageConfig> {
public constructor() {
super(brandNewLanguageConfig);
}
public getOptions(): typeof brandNewLanguageOptions {
return brandNewLanguageOptions;
}
protected makeRenderer(
renderContext: RenderContext,
untypedOptionValues: Record<string, unknown>
): BrandNewRenderer {
return new BrandNewRenderer(this, renderContext, getOptionValues(brandNewLanguageOptions, untypedOptionValues));
}
}
// 4. Renderer implementation
import { ConvenienceRenderer } from "quicktype-core";
export class BrandNewRenderer extends ConvenienceRenderer {
public constructor(targetLanguage: TargetLanguage, renderContext: RenderContext) {
super(targetLanguage, renderContext);
}
// Implement render methods here
}