microsoft / microsoft/TypeScript
`strictNullChecks` short-circuits the subsequent type checks
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Bug Report
hello, I encounter a strange bug when I use strictNullChecks: true, and here is an example:
interface A {
a: number;
}
const list: A[] = [];
list[0] ??= {}; // throw an error: Property 'a' is missing in type '{}' but required in type 'A'
list[0] = list[0] ?? {}; // the type checking not work !
list[0] = list[0] || {}; // the type checking not work !
🔎 Search Terms
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
It seems the type checking works after I close the strictNullChecks options
Playground link with relevant code
💻 Code
interface A {
a: number;
}
const list: A[] = [];
list[0] ??= {}; // throw an error: Property 'a' is missing in type '{}' but required in type 'A'
list[0] = list[0] ?? {}; // the type checking not work !
list[0] = list[0] || {}; // the type checking not work !
🙁 Actual behavior
list[0] = list[0] ?? {}; doens't throw any errors
🙂 Expected behavior
I expect that list[0] = list[0] ?? {}; should throw an error
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.
Línea de trabajo
Comienza con el TypeScript Playground enlazado y reproduce el ejemplo con strictNullChecks habilitado, comparando ??= con las asignaciones posteriores ?? y ||. Sigue el recorrido de comprobación de tipos para estas formas de asignación y añade o actualiza una prueba de regresión que muestre que asignar un objeto incompleto informa del error de propiedad faltante.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 35/100