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

Object.Partial deep and array object values #288

Open
Oikio opened this issue Jan 20, 2022 · 1 comment
Open

Object.Partial deep and array object values #288

Oikio opened this issue Jan 20, 2022 · 1 comment

Comments

@Oikio
Copy link

Oikio commented Jan 20, 2022

馃悶 Bug Report

Describe the bug

Object.Partial with deep flag changes the value of a key if it is an array by mapping array of type Type[] to (Type | undefined)[] | undefined, so it changes type type of an array.
Is it intentional or a bug? And if it is intentional, then how to avoid mapping values of the array.

Reproduce the bug

import type { Object } from 'ts-toolbelt'

const test: Object.Partial<{ foo: string[] }, 'deep'> = {} as any
test.foo // here

Expected behavior

foo?: (string | undefined)[] | undefined should be foo?: string[] | undefined

Possible Solution

Not sure if it was intentional

Screenshots

Additional context

@Oikio
Copy link
Author

Oikio commented Jan 20, 2022

Solution to exclude array which works in our case, might be useful for someone:

type ObjectFieldsOptional<T> = {
  [P in keyof T]?: T[P] extends Array<any>
    ? T[P]
    : T[P] extends object
    ? ObjectFieldsOptional<T[P]>
    : T[P]
}

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