Skip to content
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

Extended interfaces are not recognized by strict check #59

Open
rzinnatullin opened this issue Jan 26, 2022 · 2 comments
Open

Extended interfaces are not recognized by strict check #59

rzinnatullin opened this issue Jan 26, 2022 · 2 comments

Comments

@rzinnatullin
Copy link

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
Copy link
Contributor

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants