tdegrunt / jsonschema

JSON Schema validation
Other
1.82k stars 262 forks source link

bug?: Object literal may only specify known properties, and 'default' does not exist in type 'Schema' #394

Open rxliuli opened 8 months ago

rxliuli commented 8 months ago

For example, the schema defined below is legal in json, but an error will occur if the Schema of the jsonschema package is defined in ts.

import { Schema } from 'jsonschema'

const s: Schema = {
    type: 'string',
    default: 'name' // Object literal may only specify known properties, and 'default' does not exist in type 'Schema'
}

playground: https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAbzgZQMYAsCmICGcC+cAZlBCHAOQBWAzhAHY0bY4UBQbqDN8NAXCma44AXkRs4kuDACeYTAIo8owegHMKAGglSAJpiI4ArgBsYi+jhCZ2+IA


Strangely, I noticed that the type definition in the github code does contain the default field, but it does not exist in the npm package. Why is it not published?

https://github.com/tdegrunt/jsonschema/blob/b53e5853d88763b3de57be0250f46a55445789f6/lib/index.d.ts#L106

kruncher commented 3 months ago

I spotted the same issue where attempting to use this in rewrite:

rewrite: (instance, schema) => instance ?? schema.default,