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

OptionalDeep<any> shows an error #324

Open
bboure opened this issue Oct 25, 2022 · 0 comments
Open

OptionalDeep<any> shows an error #324

bboure opened this issue Oct 25, 2022 · 0 comments

Comments

@bboure
Copy link

bboure commented Oct 25, 2022

馃悶 Bug Report

Describe the bug

Using OptionalDeep on an object that contains any breaks the generated type.

Reproduce the bug

  type MyType = {
    foo: string;
    bar: any;
  };
  type OptionalType = O.Partial<MyType, 'deep'>;
  const t: OptionalType = {
    foo: 'ok',
    bar: {
      // ts error: type 'string' is not assignable to type 'OptionalDeep<any>'.
      bar: 'baz',
    },
  };


// OptionalType  evaluates to:
type OptionalType = {
    foo?: string | undefined;
    bar?: OptionalDeep<any> | undefined;
}

Expected behavior

OptionalDeep<any> should evaluate to any.

type OptionalType = {
    foo?: string | undefined;
    bar?: any;
}

Possible Solution

Change OptionalDeep to:

export declare type OptionalDeep<O> = O extends object ? {
    [K in keyof O]?: OptionalDeep<O[K]>;
} : O;

Screenshots

image

after proposed fix:

image

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