Open bsnote opened 6 years ago
Yeah, I wrote down some thoughts about that here: https://github.com/mafintosh/is-my-json-valid/pull/170#issuecomment-412480162
Unfortunately, this is not something that we can support right now, because of limitations in TypeScript. You can work around it by explicitly narrowing your types:
import createValidator = require('is-my-json-valid');
const schema = {
type: 'object' as 'object',
properties: {
name: { type: 'string' as 'string' },
age: { type: 'number' as 'number' },
},
required: [
'name' as 'name'
]
};
createValidator(schema);
Feel free to contribute to the discussion here on how to best solve this in TypeScript: https://github.com/Microsoft/TypeScript/issues/26332
TypeScript fails to compile the following snippet:
showing the following error: