DEV Community

Gustavo Henrique Silva Tenório
Gustavo Henrique Silva Tenório

Posted on

4 2

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:


Enter fullscreen mode Exit fullscreen mode

interface DepositInput {
name: string;
value : number;
createdAt: string;
}




You have oportunity to make short your codes. 
Enjoy :) 


Enter fullscreen mode Exit fullscreen mode

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Instrument, monitor, fix: a hands-on debugging session

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️