-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type 'undefined' is not assignable to type 'Schema'.ts(2345)
error with allOf+if/then+different properties
#170
Comments
Hm. Explicitly specifying I.e. this works: const a: Schema = { ... }
const b: Schema = a And this errors: const a = { ... }
const b: Schema = a |
Isolated example: type A = B[]
type B = { [id: string]: boolean }
const x: A = [
{ "X": true },
{ "Y": false }
]
const y = [
{ "X": true },
{ "Y": false }
]
const z: A = y // fails |
If I'm reading this correctly, it seems like a typescript bug, then? As a workaround, it looks like I can declare my schema in a
then...
|
I'm uncertain if this can be fixed on schemasafe side, yes. |
|
Thanks. I'd really like to be able to just copy over my schema |
@jason-curtis Hm. I'm unsure if disabling ts typechecks for schemas would be a good solution to this. |
yeah I don't think that would be a good option either. I'm able to work around the issue by casting to |
Afaik ajv just works this around by not typechecking schemas except for certain top-level properties like I'll take another look |
Hi, it seems to me that the typing for Schemas is too strict in a particular case. Please let me know if this is a bug in my code or yours:
Repro
There are a lot of things going on in my schema but here is a reduced example. If
propertyA
is 1, thenpropertyB
must be null. IfpropertyA
is 2, thenpropertyC
must be null. There are other properties present and validated at a higher level, but I'm leaving them out for this minimal example.side note: I know this particular rule set can be converted to use
oneOf
, but there are other rules in the real schema that makeallOf
more straightforward.From there, I'm just importing it and using
validator
:here's the full typescript error:
It seems like
schemasafe
expects the same properties to be named in each sub-schema, but I don't see why that would be the case.The text was updated successfully, but these errors were encountered: