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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exact incorrectly handles optional object with union type #545

Closed
defunctzombie opened this issue Jan 17, 2023 · 1 comment · Fixed by #546
Closed

Exact incorrectly handles optional object with union type #545

defunctzombie opened this issue Jan 17, 2023 · 1 comment · Fixed by #546

Comments

@defunctzombie
Copy link

defunctzombie commented Jan 17, 2023

When trying to use Exact with my function input, I am seeing the following error from typescript type checking:

Property 'union' is incompatible with index signature.
                      Type 'string' is not assignable to type 'never'.
                        Type 'string' is not assignable to type 'never'.(2345)

Here is the code which uses the Exact type with my func to validate the input object.

type ParamType = {
  outer?: {
    inner?: {
      union: "foo" | "bar";
    };
  };
};

type Input = {
  outer?: {
    inner?: {
      union: "foo" | "bar";
    };
  };
};

const input: Input = {
  outer: {
    inner: {
      union: "foo",
    },
  },
};

function func<InputT extends Exact<ParamType, InputT>>(_foo: InputT) {
  // no-op
}

func(input);

ParamType and the Input are both the same.

Playground Link

Is my expectation of what Exact should be doing here wrong?

@sindresorhus
Copy link
Owner

// @zorji

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

Successfully merging a pull request may close this issue.

2 participants