In lib/types/remove-fields-with-type.type.ts, we have:
type KeysWithType<T, Type> = {
[K in keyof T]: T[K] extends Type ? K : never;
}[keyof T];
export type RemoveFieldsWithType<T, Type> = Exclude<T, KeysWithType<T, Type>>;
I suspect that Omit should be used instead of Exclude in type RemoveFieldsWithType because Exclude<T, U> “excludes from T those types that are assignable to U”, whereas type Omit<T, K extends keyof any> “constructs a type with the properties of T except for those in type K”, which seems more what we want here.
You can see in the minimum reproduction code linked below a scenario where the type does not behaves correctly. Correct me if I've missed anything :).
Is there an existing issue for this?
Current behavior
In
lib/types/remove-fields-with-type.type.ts
, we have:I suspect that
Omit
should be used instead ofExclude
in typeRemoveFieldsWithType
becauseExclude<T, U>
“excludes fromT
those types that are assignable toU
”, whereas typeOmit<T, K extends keyof any>
“constructs a type with the properties ofT
except for those in typeK
”, which seems more what we want here.You can see in the minimum reproduction code linked below a scenario where the type does not behaves correctly. Correct me if I've missed anything :).
Minimum reproduction code
https://gist.github.com/brkaisin/a305464bb3e3a25230a51329a929bdcc
Steps to reproduce
Just having the NestJS mapped types dependency.
Expected behavior
I think we should not have the error we see in the the minimum reproduction code.
Package version
2.0.5
Node.js version
21.7.1
In which operating systems have you tested?
Other
No response