microsoft / microsoft/TypeScript

error in Variadic Tuple Types , if i reverse the partial function

Aperta
#56,970 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: check: Type Inference Help Wanted Possible Improvement
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

Type '[...any[], number]' is not assignable to type '[a: number, b: number, c: number]'.
Target requires 3 element(s) but source may have fewer.ts(2345)

🕗 Version & Regression Information
  • This is a crash
  • This changed between versions 4.23____ and nightly_
  • This changed in commit or PR _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about it___
  • I was unable to test this on prior versions because _______
⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.0-dev.20240107#code/PTAEFsEsDtPBDANqATgUwA4oPYBMCuAxmgFAkAuAnhmqAIIoqgC8qa8u20ilo80lANoBdMgDN80QuUhdQGeChlIAwkkQAeACqg0AD3JpouAM71GAGlABVXQaOnzKKwCUAfAAoSoUGIBcoB4AdCGKAOYmAYIhQVpWMdbCAJQsbqAuFt6gMQAW7LgMEQFaJCkA3lno5Pgo0IEx5PCQiIWRNinMaWLBIXkcrfEhjc2tSSQAvuKS0rJ1CkqQquouaABu2naGxmYMzjabDjuW6Z5Z-vWhKEWg0SHWg7HJqemZPg1NLVdtJeWVaNW1C5BPoFL4BawdLo9YH5AbZIYfUYTMhUGigZCsaD4cAAIzQKCmUhkckMHngAUQVhxFKshApSQCWNx+NAFR8VRqdXgoAA1KAcbzQIRkSRCFwTOQ+Cx5IplIg1IhEB5DFYAIxjMXQCX86XzOUKxArVbKtBqpJAA

💻 Code
// minimal reproduce

type Arr = readonly any[]

function partialCall<T extends Arr, U extends Arr, R>(
  f: (...args: [...T, ...U]) => R,
  ...headArgs: T
) {
  return (...tailArgs: U) => f(...headArgs, ...tailArgs)
}

function partialCallRev<T extends Arr, U extends Arr, R>(
  f: (...args: [...U, ...T]) => R,
  ...tailArgs: T
) {
  return (...headArgs: U) => f(...headArgs, ...tailArgs)
}

type l = number

function te(a: l, b: l, c: l): number {
  return a + b + c
}

const a = partialCall(te, 1)
const b = partialCallRev(te, 1)// error
🙁 Actual behavior

When I changed the order of parameters in the partialCall function, what I meant was that I wanted to first store the trailing parameters, but an error occurred.

🙂 Expected behavior

i expected it work

Additional information about the issue

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con il TypeScript Playground collegato e la riproduzione minima di partialCallRev, confrontandola con la versione funzionante di partialCall. Analizza l’inferenza dei tipi tupla variadici per l’ordine dei parametri invertito; il lavoro è completato quando la forma con parametro finale viene verificata dal type checker per la funzione mostrata con tre argomenti senza indebolire i tipi degli argomenti previsti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.