ThomasAribart / json-schema-to-ts

Infer TS types from JSON schemas 📝
MIT License
1.46k stars 31 forks source link

Can't import from JSON #200

Closed CodeFromAnywhere closed 4 months ago

CodeFromAnywhere commented 4 months ago

This works

const x= {...} as const
type T =FromSchema<typeof x>

but this doesnt

import x from "./my-schema.json"
type T =FromSchema<typeof x>

is there something that can fix this? It would be much better for my usecase.

After some research, I think this would be needed to pass first: https://github.com/microsoft/TypeScript/issues/32063

ThomasAribart commented 4 months ago

Hi @CodeFromAnywhere !

As you've seen, this is an issue with TypeScript rather than json-schema-to-ts, there is a page in the FAQ about it: https://github.com/ThomasAribart/json-schema-to-ts/blob/main/documentation/FAQs/does-json-schema-to-ts-work-on-json-file-schemas.md

TL:DR: There's not much we can do for the moment, just a small workaround which is not ideal.