Variadic function argument not getting inferred correctly
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- Plutôt claire
- Activité
- À l'abandon
- Stack technique
- typescript
- Domaine
- compilers
Piste de recherche
Commencez par l’exemple TypeScript Playground lié et reproduisez l’erreur d’affectation impliquant le tuple variadique générique et l’argument FetchQueryOptions optionnel. Suivez le comportement de l’inférence des types et de l’assignabilité pour la signature de la fonction ; le travail est terminé lorsque l’exemple accepte l’implémentation et infère les arguments variadiques comme [string, number], tout en conservant le paramètre overrides optionnel.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Bug Report
I am trying to create a function type where the args are some variadic number of generic args, T, and the last arg is an optional overrides variables: overrides?: FetchQueryOptions<R>, but the variadic args,T, are unable to be assigned to any type. See below for code example.
🔎 Search Terms
Generic functions variadic tuple type inference spread
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries
⏯ Playground Link
Playground link with relevant code
💻 Code
interface FetchQueryOptions<R> {
fetchFunc?: () => R;
}
export interface IGetQueryFunc<R> {
<T extends any[]>(
...args: [...rest: T, overrides?: FetchQueryOptions<R>]
): FetchQueryOptions<R>;
}
const getUserPostQuery: IGetQueryFunc<string> = (
userId: string,
postId: number,
overrides?: FetchQueryOptions<string>
): FetchQueryOptions<string> => {
return {
fetchFunc: () => 'some data:' + `${userId}` + `${postId}`,
...overrides
}
};
🙁 Actual behavior
I am getting the below error:
Type '(userId: string, postId: string, overrides?: FetchQueryOptions<string> | undefined) => FetchQueryOptions<string>' is not assignable to type 'IGetQueryFunc<string>'.
Types of parameters 'userId' and 'rest' are incompatible.
Type '[...rest: T, overrides?: FetchQueryOptions<string> | undefined]' is not assignable to type '[userId: string, postId: string, overrides?: FetchQueryOptions<string> | undefined]'.
Variadic element at position 0 in source does not match element at position 0 in target.(2322)
🙂 Expected behavior
I expect the ...rest: T to be correctly inferred as [string, number]. and ...args to be inferred as [string, number, FetchQueryOptions<string> | undefined]
- Langage dominant
- Go
- Étoiles
- 111k
- Forks
- 14.4k
- Merge moyen
- 1 j 19 h
- PR mergées (30 j)
- 117
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de microsoft/TypeScript
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
microsoft/TypeScript#64322 · 2 commentaires · 1 réaction · 2 personnes assignées ·
-
Possible Improvement
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
microsoft/TypeScript#64278 · 1 commentaire · 1 réaction ·
-
Docs
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
microsoft/TypeScript#64118 · 1 commentaire ·
-
Difficulté 1/5 Moins d'une heure Accessibilité débutants 88/100
microsoft/TypeScript#64094 ·
-
Docs
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
microsoft/TypeScript#63959 · 5 commentaires ·
Toutes les issues de microsoft/TypeScript
Issues similaires
-
optimization optimization:agents-md-curator
Difficulté 2/5 1-3 heures Accessibilité débutants 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
blinklabs-io/bursa#904 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 commentaires ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 90/100