Search Terms
omit strict
Suggestion
The new Omit type does not restrict the omitted keys to be keys actually present on the given type. There should be some avenue to express "omit, but only with keys that are present", likely either a change to Omit or some other Omit-like type.
Use Cases
Copied from pelotom/type-zoo#31.
The benefit that a stricter type has is primarily:
- Preventing typos.
- Allowing the compiler to pick up on rename refactors automatically.
Currently, permissive Omit acts as a "barrier" that prevents rename refactors from passing through, which means that any such refactor generates whole bunches of errors that have to be manually fixed. If the field in question is optional, this can actually introduce bugs.
And some further color:
I generally use Omit with string literal unions (as opposed to, say, generic types that extends string), because I often use them for defining higher-order React components that wrap another component except for this one prop. As such, in my use case, I never want a permissive Omit.
Examples
interface ImplementationDetailProps {
publiclyVisibleFoo: Foo;
filePrivateBar: Bar;
}
class ImplementationDetail extends React.Component<ImplementationDetailProps> { ... }
export type PublicProps = Omit<ImplementationDetailProps, "filePrivateBar">;
export class Public extends React.Component<PublicProps> { ... }
Checklist
My suggestion meets these guidelines:
Search Terms
omit strict
Suggestion
The new
Omittype does not restrict the omitted keys to be keys actually present on the given type. There should be some avenue to express "omit, but only with keys that are present", likely either a change toOmitor some otherOmit-like type.Use Cases
Copied from pelotom/type-zoo#31.
The benefit that a stricter type has is primarily:
Currently, permissive Omit acts as a "barrier" that prevents rename refactors from passing through, which means that any such refactor generates whole bunches of errors that have to be manually fixed. If the field in question is optional, this can actually introduce bugs.
And some further color:
I generally use
Omitwith string literal unions (as opposed to, say, generic types thatextends string), because I often use them for defining higher-order React components that wrap another component except for this one prop. As such, in my use case, I never want a permissiveOmit.Examples
Checklist
My suggestion meets these guidelines: