Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Behavior of Pxth<V | null | undefined> is wrong when settings type. #28

Open
AlexShukel opened this issue Sep 10, 2023 · 0 comments
Open
Labels
bug Something isn't working

Comments

@AlexShukel
Copy link
Contributor

Describe the bug
The bug occurs when trying to set some value on inner path of Pxth<V | undefined | null> (where V is some generic object type). By default, lodash's set function when executed in the same manner _.set({ a: null }, ['a', 'b'], 42) creates empty object in-place recursively, overriding any primitive value. However, new constructed object is not of type V | undefined | null.

So, Pxth should know which type it can GET and which type it can SET.

To Reproduce

it('...', () => {
  type FormValues = {
      value: {
          a: string;
          b: number;
      } | null;
  };

  const values: FormValues = {
      value: null,
  };
  const paths = createPxth<FormValues>([]);

  // This should throw ts error as we are trying to set value on children of nullable object.
  deepSet(values, paths.value.a, 'aaa');

  console.log(values.value); // logs { a: 'aaa' }
});

Expected behavior
TS error should be there when trying to set value on children of nullable object.

Additional context
In addition, this bug is related to another problem:

  • When initial value differs from real (for example, if server returns null for initial value of text field, however we should not be able to set null manually in text field)
@AlexShukel AlexShukel added the bug Something isn't working label Sep 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant