angus-c/just

[feat] more accurate type for just-curry-it

Open

#504 opened on Sep 29, 2022

View on GitHub
 (1 comment) (0 reactions) (0 assignees)JavaScript (5,494 stars) (228 forks)batch import
help wanted

Description

Package

just-curry-it@5.2.1

Example

type MP2 = {
  a1: "a2";
  b1: "b2";
};
type MP3 = {
  a1: "a3";
  b1: "b3";
};
type MR = {
  a1: "ar";
  b1: "br";
};
function foo<K extends keyof MP2>(p1: K, p2: MP2[K], p3: MP3[K]): MR[K] {
  return { p1, p2, p3 } as any;
}

Actual

// no errror
curry(foo)('a1')('b2')

// "ar" | "br"
const r = curry(foo)('a1')('a2')('a3')
void r

Expected

// @ts-expect-error
curry(foo)('a1')('b2')

// "ar"
const r = curry(foo)('a1')('a2')('a3')
void r

Related

RyanCavanaugh said it is possible.

https://github.com/microsoft/TypeScript/issues/50991#issuecomment-1262574411

Contributor guide