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

Except no longer prevents the omitted keys to be keys present on the given type #360

Closed
nvdbleek opened this issue Feb 7, 2022 · 5 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@nvdbleek
Copy link

nvdbleek commented Feb 7, 2022

The change for #263 in release v2.3.2 no longer prevents the use of the keys in the Except.

The following code no longer gives an error:

import { Except } from 'type-fest';

interface WithBar {
  foo: string;
  bar: number;
}

type WithoutBar = Except<WithBar, 'bar'>;

const withBar = { foo: 'Hell World', bar: 42 };
// The following assignment should result in an error, but no longer results in an error after the change of #263
const withoutBar: WithoutBar = withBar; 

Before 2.3.2 type-fest used never and you weren't allowed to assign an object that contains a key that was added to the except list. The documentation still states that Except is a stricter version of Omit, but I don't think it currently is.

Conceptually type-fest was generating the following code before 2.3.2:

interface WithBarNever {
  foo: string;
  bar: never;
}

// Results in a compile error as the object should not contain a `bar` property
const withoutBarNever: WithBarNever = withBar;
@nvdbleek
Copy link
Author

nvdbleek commented Feb 7, 2022

I've created a codesandbox demonstrating the 'error' https://codesandbox.io/s/wizardly-hertz-wbv99?file=/src/index.ts

Line 12 doesn't contains a compile error (the old implementation used never and resulted in a compile error, see line 19 for this case)

@sindresorhus
Copy link
Owner

// @szmarczak

@sindresorhus sindresorhus added bug Something isn't working help wanted Extra attention is needed labels Jun 30, 2022
@szmarczak
Copy link
Contributor

The code you provided in codesandbox simplifies to

const withBar = { foo: "Hell World", bar: 42 };

interface WithBarNever {
  foo: string;
  bar: never;
}

const withoutBarNever: WithBarNever = withBar;

which doesn't use Except at all.

@skarab42
Copy link
Collaborator

I am closing this issue, it seems impossible to reproduce the error with the old or new version. Feel free to reopen this issue if you have a reproducible example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants