microsoft / microsoft/TypeScript

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

Open
#56,970 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: check: Type Inference Help Wanted Possible Improvement
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔎 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked TypeScript Playground and the minimal reproduction for partialCallRev, comparing it with the working partialCall version. Investigate variadic tuple type inference for the reversed parameter order; done when the trailing-parameter form type-checks for the shown three-argument function without weakening the expected argument types.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.