-
-
Notifications
You must be signed in to change notification settings - Fork 575
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
is not strict
#556
Comments
This is probably because TypeScript has a design decision that causes it to only check for excess properties when an object is defined using an object literal syntax. It is possible to restrict import { Except } from "type-fest";
type StrictExcept<T, K extends keyof T> = Except<T, K> & Partial<Record<K, never>>;
type Foo = {
a: number;
b: string;
c: boolean;
};
type FooWithoutA = StrictExcept<Foo, 'a'>;
const foo: Foo = {
a: 1,
b: 'b',
c: true
}
const fooWithoutA: FooWithoutA = foo; // error If relevant, I would be happy to submit a PR and fix the original |
Cool, your solution worked. Thank you! |
@orimiles5 Maybe adding an Lines 5 to 14 in a065865
The default behavior would be the updated strict version, and users could opt in to the non-strict |
Great idea. I’ll work on it. Thank you! |
playground link
Is this intended behavior? if yes, how can i restrict
foo
for being assign tofooWithoutA
?Thank you.
The text was updated successfully, but these errors were encountered: