Skip to content

Generated d.ts file doesn't create references to schema correctly #490

Open
@kbfirebreather

Description

@kbfirebreather

My schema is pretty large, but I whittled it down to what's attached that seems to generate the issue.

My code is as follows:

import { compileFromFile } from 'json-schema-to-typescript';

...

const ts = await compileFromFile(file);
const name = path.basename(file, '.json');
await writeFile(`${outDir}/${name}.d.ts`, ts);

Where file is the .json file.

Attached is typescript-demo-parent.json which is the input file that gets passed to compileFromFile, and the resulting output typescript-demo-parent.d.ts. In the output, results->matches is referenced as Matches1[]. From the exports, Matches1 is a ScoredItem, where as Matches is Matches1 & Matches2. Matches2 has the id required property that is defined in the json file. From my point of view, results->matches should really be Matches[] rather than Matches1[]. When I enforce linting against this object in code, and try to set .id, it complains that it's not a valid property.

I uploaded the files with the .log extension so github would accept me uploading them. Remove the extension to reproduce the issue.

typescript-demo-parent.json.log

typescript-demo-parent.d.ts.log

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions