microsoft / microsoft/TypeScript
`Error.stack` type definition in lib.es5.d.ts is incorrect / `exactOptionalPropertyTypes` incompatible
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Bug Report
🔎 Search Terms
Error.stack, exactOptionalPropertyTypes, ErrnoException
🕗 Version & Regression Information
- This is a type issue
- This changed in #8705 but it took until the
4.4release for it to surface, thanks toexactOptionalPropertyTypesand it makingErrorincompatible with a correctedError-subclass in@types/node: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/55425 - This is the behavior in every version I tried, and I reviewed the FAQ for entries about es5
⏯ Playground Link
Playground link with relevant code which is valid according to the ECMAScript spec and basically every other JS spec out there as .stack isn't standardized (as far as eg. MDN knows at least)
Edit: @ljharb has an ECMAScript Stage 1 proposal for an Error Stacks spec.
💻 Code
interface MyCoolStack {
line: string
}
interface MyError extends Error {
stack: MyCoolStack
}
🙁 Actual behavior
Got error:
Interface 'MyError' incorrectly extends interface 'Error'.
Types of property 'stack' are incompatible.
Type 'MyCoolStack | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
🙂 Expected behavior
One of two:
Either that it passes completely...- ...or at least that it complains the same as it does with
exactOptionalPropertyTypesturned off:
Interface 'MyError' incorrectly extends interface 'Error'.
Types of property 'stack' are incompatible.
Type 'MyCoolStack | undefined' is not assignable to type 'string | undefined'.
Type 'MyCoolStack' is not assignable to type 'string'.
Edit: The ECMAScript Stage 1 proposal for an Error Stacks spec defines that the stack should be of type string|undefined, which makes the current type of stack?:string wrong and should be replaced with stack?:string|undefined if one agrees with that specs view of the current state of Error stacks.
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
Inspecciona la declaración de Error en lib.es5.d.ts y reproduce la incompatibilidad informada usando el TypeScript Playground enlazado, con exactOptionalPropertyTypes habilitado y deshabilitado. Compara los diagnósticos resultantes con el comportamiento esperado y la propuesta enlazada de Error Stacks; se considera terminado cuando la declaración refleja la semántica elegida por el proyecto para Error.stack.
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
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100