Open
Description
A schema of:
{
"type": "object",
"properties": {
"$schema": {
"description": "The JSON schema reference.",
"type": "string"
},
},
"additionalProperties": {
"type": "object"
}
}
resolves to:
export interface MySchema {
/**
* The JSON schema reference.
*/
$schema?: string;
[k: string]: {
[k: string]: unknown;
};
}
which is an incompatible type, as $schema
clearly doesn't follow { [k: string]: unknown }
.
You can see the error in the typescript playground.
I encountered this here: https://dprint.dev/schemas/v0.json which is the schema for the dprint configuration. (cc @dsherret)
A potential fix is to generate additionalProperties
as:
[k: string]: {
[k: string]: unknown;
} | unknown;
Test code:
const { compile } = require('json-schema-to-typescript');
// or, compile a JS object
let mySchema = {
"type": "object",
"properties": {
"$schema": {
"description": "The JSON schema reference.",
"type": "string"
},
},
additionalProperties: {
type: "object"
}
}
compile(mySchema, 'MySchema')
.then(console.log)