microsoft / microsoft/TypeScript
Interface definition utilizing `this` type errors out only in specific cases and only when a member is accessed, not before
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
Bug Report
🔎 Search Terms
"interface this"
"interface this" intersection
"is referenced directly or indirectly"
"is referenced directly or indirectly in its own type annotation."
ts(2502)
HKT circular
intersection circular
🕗 Version & Regression Information
- This changed between versions 3.8.3 and 3.9.7
⏯ Playground Link
Playground link with relevant minimal code and commented version
💻 Code
With version 4.2.3
interface foo<T> { a: T; b: this["a"] };
// ^- 'b' is referenced directly or indirectly in its own type annotation.ts(2502)
type intersection = foo<string> & foo<number>; // Works in some cases, shown in linked playground
type induces_error = intersection["a"]; // Comment this out and the error in the interface goes away
Found when messing with ways to simulate HKTs with this type, which itself seems to be considered a valid use case, per:
https://github.com/microsoft/TypeScript/issues/40928 https://github.com/microsoft/TypeScript/pull/40967
🙁 Actual behavior
- Interface definition erroring out for an unclear reason when using said interface later down the line, but not before. It doesn't seem right that the definition shows an error that wasn't there before by just accessing a property.
- Error itself is questionable, worked in 3.8.3, and a similar use case seems to be covered by the test (#40967) linked above?
🙂 Expected behavior
- Interface definition either always errors, or an error doesn't pop up only when using the interface definition only in specific ways.
- Additionally, reason for circularity error is not immediately obvious to me, and it seems it might a regression since 3.8.3?
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 el ejemplo mínimo de foo<T>/intersection, reproduciéndolo en las versiones de TypeScript mencionadas 3.8.3, 3.9.7 y 4.2.3. Lee el contexto relacionado en los issues #40928 y en el pull request #40967; se considera terminado cuando el comportamiento se haya diagnosticado de forma coherente y la regresión o circularidad reportada se haya resuelto o explicado claramente.
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
- Activo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100