An Interest In:
Web News this Week
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
April 12, 2022 09:13 pm GMT
Original Link: https://dev.to/gustavohst/type-tip-to-shrink-you-code-6c3
Tip to shrink you code using "Omit" to create interfaces!
Hey guys! I want to share one tip to you!
Imagine that you have one interface called by "Deposit" to create using: Id, Name, Value, CreatedAt properties.
Usually we will create somethink like this:
interface Deposit{ id: number; name: string; value : number; createdAt: string;}
And if you need create another interface from "Deposit". For example, create a new one without the Id called by "DepositInput". We can use the Omit sintaxe. :D
type DepositInput = Omit<Deposit, 'id' >
instead:
interface DepositInput { name: string; value : number; createdAt: string;}
You have oportunity to make short your codes.
Enjoy :)
Original Link: https://dev.to/gustavohst/type-tip-to-shrink-you-code-6c3
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To