Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.
This repository was 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

@AlexShukel

Description

@AlexShukel

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions