Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Change the value type of Record from T to T | undefined #215

Open
Eyal-Shalev opened this issue Jan 5, 2025 · 0 comments
Open

Change the value type of Record from T to T | undefined #215

Eyal-Shalev opened this issue Jan 5, 2025 · 0 comments

Comments

@Eyal-Shalev
Copy link

Currently Record<K,V> is defined as follows:

type Record<K extends keyof any, T> = {
    [P in K]: T;
};

I suggest changing it to this:

type Record<K extends keyof any, T> = {
    [P in K]: T | undefined;
};

This allows TypeScript to protects us better from unchecked indexed access.

I could use the noUncheckedIndexedAccess but it doesn't play nice with the @typescript-eslint/no-unnecessary-condition eslint rule, as according to the type checker myRecord[someKey] will always return a T.

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

No branches or pull requests

1 participant