Omit in TypeScript #typescript

preview_player
Показать описание
Become a TypeScript Wizard with my free beginners TypeScript Course:

Follow Matt on Twitter

Join the Discord:

Рекомендации по теме
Комментарии
Автор

this was so peaceful
i forgot its typescript

Dev-Siri
Автор

Love this in typescript. I most commonly use this when working in React, and I have an "id" prop that can be a string/number, but also want to extend the type to include div props.

leopettecrew
Автор

Great short. I still have trouble understanding satisfies tho ;-;

guilherme
Автор

Hey Matt, something I keep having issues with is recursive types. As a simpler example, say a nested omit which takes a type A and a type B with matching optional keys of type A that can be marked as true. The output of the type only keeps keys with their type found in type A if the keys are marked true in type B. (In my actual usecase it was a "deep partial unless", where all keys are optional except the ones marked in B).

I'd love to see some tips in tricks on how to break recursive problems like these, and more complex ones down.

janglad
Автор

I love when you need to program types to be able to program software. Super productive! 😊

teamgartz-motorsports
Автор

1 thing i don't like about "Omit" is they don't auto complete the 2nd parameters like "Pick", so i build my own Omit like this

export type LooseAutoComplete<TSuggest extends TLoose, TLoose = unknown> = TSuggest | NonNullable<unknown>;


export type ImprovedOmit<TObject, TKeys extends LooseAutoComplete<keyof TObject>> = Pick<
TObject,
Exclude<keyof TObject, TKeys>
>;

Basically i copy the original Omit type from TS and use LooseAutoComplete to provide suggestions. I don't know why TS teams didn't do this, maybe it's because performance issues or backward compatibility?

anhdunghisinh
Автор

That was zen and all but WHERE'S YOUR VOICE

juliohintze
Автор

Do you just animate a pointer in editing?? That's so pleasant

sbudekc
Автор

I like it better with you just chilling in the corner talking though something :(

shaded
Автор

Hey Matt, since omit doesn’t autocomplete the second parameter, can you make a new OmitStrict type that does?

athulgeorge