Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
quicktype-core: generating TypeScript interfaces that allow extra unknown properties when parsing, without throwing an exception

I'm using NPM package: https://www.npmjs.com/package/quicktype-core to generate TypeScript interfaces from JSON samples.

Here's a simple example of the code that generates the interfaces:

const sample_object = {
    prop_a: 'value A',
    prop_b: 'value B',
};

const jsonInput = jsonInputForTargetLanguage('typescript');
await jsonInput.addSource({
    name: 'MyNewInterface',
    samples: [JSON.stringify(sample_object)],
});
const inputData = new InputData();
inputData.addInput(jsonInput);

const result = await quicktype({
    inputData,
    lang: 'typescript',
    inferDateTimes: false,
    alphabetizeProperties: true,
    inferEnums: false,
    rendererOptions: {},
});

// Display generated interface:
const generated_code = result.lines.join('\n');
console.log(generated_code);

The interface that it generates works when parsing new data that ONLY contains the properties it knows about. But if you try to parse some data that contains any extra fields/properties, it throws an exception, e.g. sample data:

const sample_object = {
    prop_a: 'value A',
    prop_b: 'value B',
    new_extra_property: 'value for new_extra_property',
};

Will throw exception:

Invalid value "value for new_extra_property" for type false

How can I configure quicktype-core to generate code that will NOT throw exceptions when data contains extra unknown fields?

I've tried trawling through the quicktype source code, and came across a couple of rendererOptions called additionalProperties + runtimeTypecheckIgnoreUnknownProperties ... but trying to set those as either true or a string doesn't make any difference at all to the code it generates.

Setting to true (actually gives TypeScript errors for the code, even though many quicktype-option renderedOptions are actually bools, and they've worked for other settings):

const result = await quicktype({
    inputData,
    lang: 'typescript',
    inferDateTimes: false,
    alphabetizeProperties: true,
    inferEnums: false,
    rendererOptions: {
        additionalProperties: true,
        runtimeTypecheckIgnoreUnknownProperties: true,
    },
});

Setting a string (keeps the TypeScript checking happy):

const result = await quicktype({
    inputData,
    lang: 'typescript',
    inferDateTimes: false,
    alphabetizeProperties: true,
    inferEnums: false,
    rendererOptions: {
        additionalProperties: 'string',
        runtimeTypecheckIgnoreUnknownProperties: 'string',
    },
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!