microsoft / microsoft/TypeScript
TS2769 : Function.bind
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
function bind
🕗 Version & Regression Information
TypeScript 4.1 & 4.2-beta
⏯ Playground Link
💻 Code
type Funcs = {
first (value: string): void;
second (value: number): void;
}
type Store = {
commit <Name extends keyof Funcs> (
name: Name,
...args: Parameters<Funcs[Name]>
): void;
}
type Func <Name extends keyof Funcs> = (
...args: Parameters<Funcs[Name]>
) => void;
declare const store: Store;
function commit<Name extends keyof Funcs> (name: Name): Func<Name> {
// error
return store.commit.bind(undefined, name);
}
function commit2<Name extends keyof Funcs> (name: Name): Func<Name> {
return function (...args: Parameters<Func<Name>>) {
// correct
store.commit(name, ...args);
}
}
🙁 Actual behavior
(method) commit<Name extends keyof Funcs>(name: Name, ...args: Parameters<Funcs[Name]>): void
No overload matches this call.
Overload 1 of 6, '(this: (this: undefined, arg0: Name, ...args: [value: string] | [value: number]) => void, thisArg: undefined, arg0: Name): (...args: [value: string] | [value: number]) => void', gave the following error.
The 'this' context of type '<Name extends keyof Funcs>(name: Name, ...args: Parameters<Funcs[Name]>) => void' is not assignable to method's 'this' of type '(this: undefined, arg0: Name, ...args: [value: string] | [value: number]) => void'.
Types of parameters 'args' and 'args' are incompatible.
Type '[value: string] | [value: number]' is not assignable to type 'Parameters<Funcs[Name]>'.
Type '[value: string]' is not assignable to type 'Parameters<Funcs[Name]>'.
Overload 2 of 6, '(this: (this: undefined, ...args: Name[]) => void, thisArg: undefined, ...args: Name[]): (...args: Name[]) => void', gave the following error.
The 'this' context of type '<Name extends keyof Funcs>(name: Name, ...args: Parameters<Funcs[Name]>) => void' is not assignable to method's 'this' of type '(this: undefined, ...args: Name[]) => void'.
Types of parameters 'name' and 'args' are incompatible.
Type 'Name[]' is not assignable to type '[name: Name, ...args: Parameters<Funcs[Name]>]'.
Target requires 2 element(s) but source may have fewer.(2769)
🙂 Expected behavior
The function commit works correctly as the function commit2. I'm a bit confused and sorry if this bug has been reported.
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 error TS2769 usando el ejemplo de commit genérico y store.commit.bind con TypeScript 4.1 o 4.2-beta. No se nombra ningún archivo del repositorio ni ninguna prueba, así que sigue el tratamiento que hace el compilador de Function.bind y las tuplas de parámetros genéricas; se considera terminado cuando commit pasa la comprobación de tipos con el mismo comportamiento que commit2.
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
- 35/100