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

unclear how to make function argument check produce the same errors as variable assignment #29578

Open
helios1138 opened this issue Jan 25, 2019 · 0 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@helios1138
Copy link

helios1138 commented Jan 25, 2019

in the following code

type A = {
  a?: number
  b?: number
}

type B = {
  a?: number
  knownField?: number
}

type C = {
  a?: A,
  knownField?: number | [A, B] | A
}

const c: C = {
  a: {
    a: 1,
    b: 1,
  },
  knownField: [{ a: 1 }, {
    knownField: 1,
    unknownField: 1,
  }],
}

const fn = (c: C) => {}

fn({
  a: {
    a: 1,
    b: 1,
  },
  knownField: [{ a: 1 }, {
    knownField: 1,
    unknownField: 1,
  }],
})
  • in the case of variable assignment it correctly highlights the unknownField and produces a nice error that says Object literal may only specify known properties, and 'unknownField' does not exist in type 'B'.
  • but in the case of the same value passed as a function argument (of the same type) it highlights the top-level field and a different, less readable error Type '({ a: number; } | { b: number; unknownField: number; })[]' is missing the following properties from type '[A, B]': 0, 1

am I missing something? is there a way to make sure I get the same error and highlighting in both cases?

in typescript playground:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

3 participants