> For the complete documentation index, see [llms.txt](https://productsway.gitbook.io/typescript-tips/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://productsway.gitbook.io/typescript-tips/notes/housecor-1581638360543600640.md).

# housecor - 1581638360543600640

![housecor](https://pbs.twimg.com/profile_images/1525874017630035970/veQQouGw_normal.jpg) Cory House ([@housecor](https://twitter.com/housecor)) - October 16, 2022 at 9:29 PM

TypeScript tip:

Avoid making a property optional when the property isn’t valid in a certain case.

Instead, declare 2 separate types, and use Omit to avoid copy/paste.

Example: Many objects lack an id until they're saved. So declare a separate "Unsaved" type.

[#typescript](https://twitter.com/hashtag/typescript) [pic.twitter.com/Wzzx3DtYEE](https://twitter.com/housecor/status/1581638360543600640/photo/1)

![// Avoid making a property optional to support two separate scenarios. // Doing so redunces type safety. type User = {   // Making id optional since unsaved users don't have an id yet. 👎   id?: number;   name: string;   email: string; }   // Instead, declare separate types. Then each scenario is fully type safe. 👍  type User = {   id: number;   name: string;   email: string; }  // Separate type for unsaved users. // Deriving from the User type via Omit to keep types clean and lean. type UnsavedUser = Omit\<User, "id">;](https://pbs.twimg.com/media/FfMalUHXEAIELCa.jpg)

[Tweet link](https://twitter.com/housecor/status/1581638360543600640)

[Thread by @housecor on Threadify Reader App](https://threadify.productsway.com/thread/1581638360543600640)
