microsoft / microsoft/TypeScript

Module augmentation allows non-identical type parameters as long as there are defaults, but doesn't pass them

Abierto
#55,026 0 comentarios 2 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Bug Domain: Binder Help Wanted
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
  • module augmentation
  • callback generic type
🕗 Version & Regression Information

Currently using typescript 5.1.6, but AFAIK this behavior was the same in previous versions. This also occurs on the Nightly.

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about generics (and the rest of the FAQ)
⏯ Playground Link

Playground link with relevant code

💻 Code
interface Chainable<Subject = any> {
    within(fn: (prevSubject: Subject) => Chainable<Subject>): Chainable<Subject>;
}

interface Chainable<Subject = any, ExtraType = undefined> {
    within(fn: (prevSubject: Subject, extra: ExtraType) => Chainable<Subject>): Chainable<Subject, ExtraType>;
}

interface ChainableLike<Subject = any, ExtraType = undefined> {
    within(fn: (prevSubject: Subject) => Chainable<Subject>): Chainable<Subject>;
    within(fn: (prevSubject: Subject, extra: ExtraType) => Chainable<Subject>): Chainable<Subject, ExtraType>;
}

type ChainableWithSecondType = Chainable<string, string>;
type Wrong = ChainableWithSecondType['within'];
type Correct = ChainableLike<string, string>['within'];
🙁 Actual behavior

If you omit the default on the added generic ExtraType, you get an error: All declarations of 'Chainable' must have identical type parameters. But when there's a default, it allows the type parameters to be different, but doesn't properly infer types.
image

Typescript does not produce any errors, but when you mouseover Wrong, it shows the type of extra to be ExtraType.
image

🙂 Expected behavior

Either TS should completely ban adding an optional extra type parameter, or it should properly infer type (i.e. mousing over Wrong should produce the same as mousing over Correct)

image

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduce el comportamiento utilizando el TypeScript Playground enlazado y compara los tipos Wrong y Correct del ejemplo proporcionado de aumento de módulos. Sigue cómo el compilador comprueba listas de parámetros genéricos diferentes cuando los parámetros añadidos tienen valores predeterminados; después, añade cobertura para el comportamiento indicado y verifica que los parámetros adicionales opcionales se rechacen o se infieran de forma coherente.

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
Bastante claro
Aptitud para principiantes
38/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.