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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error for OptionalKeys<T> & WritableKeys<T> #282

Open
iliubinskii opened this issue Dec 22, 2021 · 0 comments
Open

Error for OptionalKeys<T> & WritableKeys<T> #282

iliubinskii opened this issue Dec 22, 2021 · 0 comments

Comments

@iliubinskii
Copy link

馃悶 Bug Report

Describe the bug

OptionalKeys<T> & WritableKeys<T> causes error - see code snippet below.

Reproduce the bug

export type OptionalToUndefined<T extends object> = {
  readonly [K in OptionalKeys<T> & ReadonlyKeys<T>]: T[K] | undefined;
} & {
  [K in OptionalKeys<T> & WritableKeys<T>]: T[K] | undefined;
} & {
  readonly [K in RequiredKeys<T> & ReadonlyKeys<T>]: T[K];
} & {
  [K in RequiredKeys<T> & WritableKeys<T>]: T[K];
};

Expected behavior

OptionalKeys separately can be used as a key.
WritableKeys separately can be used as a key.

So, their combination should also be usable.

Possible Solution

I use this as temporary solution

export type OptionalToUndefined<T extends object> = {
  readonly [K in OptionalKeys<T> & ReadonlyKeys<T>]: T[K] | undefined;
} & {
  [K in Exclude<OptionalKeys<T>, ReadonlyKeys<T>>]: T[K] | undefined;
} & {
  readonly [K in RequiredKeys<T> & ReadonlyKeys<T>]: T[K];
} & {
  [K in RequiredKeys<T> & WritableKeys<T>]: T[K];
};

Screenshots

Screenshot

Additional context

This error may depend on typescript configuration. If you can't reproduce I will upload reproduction repo.

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