microsoft / microsoft/TypeScript
unclear how to make function argument check produce the same errors as variable assignment
Abierto
@sandersn ya está trabajando en esto.
Desde el 25/1/2019.
Needs Investigation
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
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
unknownFieldand produces a nice error that saysObject 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:

Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Evaluación
Este issue todavía no se ha evaluado.