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

OverrideProperties marks all properties optional #704

Closed
crizo23 opened this issue Oct 12, 2023 · 6 comments
Closed

OverrideProperties marks all properties optional #704

crizo23 opened this issue Oct 12, 2023 · 6 comments

Comments

@crizo23
Copy link

crizo23 commented Oct 12, 2023

The resulting type has all properties optional. I don't think this is intended?

I used the example from the docs:

type Foo = {
	a: string
	b: string
}
type Bar = OverrideProperties<Foo, {b: number}>
//=> {a: string, b: number}

I'm on typescript 5.2.2 and see a and b optional in Bar:

type Bar = {
    a?: string;
    b?: number;
}

Screenshot 2023-10-11 at 9 35 59 PM

@sindresorhus
Copy link
Owner

// @jinta4020 @nidomiro

@crizo23
Copy link
Author

crizo23 commented Oct 12, 2023

Same issue with Merge

@henriqueinonhe
Copy link
Contributor

It's caused by the strict option in your tsconfig.json not being set to true.

@crizo23
Copy link
Author

crizo23 commented Oct 16, 2023

It's caused by the strict option in your tsconfig.json not being set to true.

confirmed! Thanks for the update.

@crizo23 crizo23 closed this as completed Oct 16, 2023
@crizo23
Copy link
Author

crizo23 commented Oct 16, 2023

I am confused though why this tsconfig setting would affect the types generated by type-fest? @henriqueinonhe Is there a quick/easy explanation? thanks

@henriqueinonhe
Copy link
Contributor

It doesn't affect the types generated themselves, but rather how Typescript checks types.

The strict option, when enabled, turns on several behaviors that make type checking "stricter".

In this case, it's probably caused especfically by the strictNullChecks flag.

Right now I won't be able to pinpoint the exact reason why strictNullChecks = false causes the problem you encountered, but the thing is that when that flag is turned off, it basically "ignores" null and undefined, effectivelly changing how the type checking works.

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

No branches or pull requests

3 participants