Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Handling generic typing for D.toPairs() #82

Open
SamCB-CT opened this issue May 26, 2023 · 0 comments
Open

Handling generic typing for D.toPairs() #82

SamCB-CT opened this issue May 26, 2023 · 0 comments

Comments

@SamCB-CT
Copy link

SamCB-CT commented May 26, 2023

Based on the current definition:

function toPairs<T, K extends string | number>(dict: Record<K, T>): Array<readonly [string, T]>

The first element in each pair is a string but it should use the generic type K. For example:

type Keys = 'foo' | 'bar' | 'baz';

const input: Record<Keys, number> = {foo: 42, bar: 0, baz: -1};
const output = D.toPairs(input);

The definition for output in the .d.ts becomes:

declare const output: (readonly [string, number])[];

But I'd expect it to be:

declare const output: (readonly [Keys, number])[];

Typescript Playground Example

By updating the definition to:

function toPairs<T, K extends string | number>(dict: Record<K, T>): Array<readonly [K, T]>;

This seems to fix it (see playground) but I'm not enough across how the gentype rescript stuff works to be able to make a PR.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant