Extended interfaces are not recognized by strict check
rzinnatullin opened this issue · 2 comments
rzinnatullin commented
Suppose we have the following interfaces:
export interface FieldFilter {
fieldName: string
condition: FieldFilterCondition
}
export interface FieldFilterCondition {
type: FieldFilterConditionType
invert?: boolean
}
export enum FieldFilterConditionType {
isNull = 'isNull',
in = 'in'
}
export interface FieldFilterConditionIsNull extends FieldFilterCondition {
type: FieldFilterConditionType.isNull
}
export interface FieldFilterConditionIn extends FieldFilterCondition {
type: FieldFilterConditionType.in
values: Value[]
}
Strict check on the following JSON will fail:
{
"fieldName":"SomeFieldName",
"condition":{
"type":"in",
"values":[
"Some value"
]
}
}
Error message:
...
value.condition.values is extraneous
...
alexmojaki commented
This sounds like a duplicate of #46
In pure TypeScript, this is also an error:
const cond: FieldFilterCondition = {
type: FieldFilterConditionType.in,
values: [1, 2]
}
That doesn't mean this issue should be dismissed, I even said myself:
this is all hypothetical until an actual user complains
and here we are.
rzinnatullin commented
Thank you @alexmojaki for the answer.
I think it is very clear why strict check fails - it simply does not know what exact derived type to use here.
The solution I can imagine is to allow defining a type selector for the checker.