DEV Community

Gustavo Henrique Silva Ten贸rio
Gustavo Henrique Silva Ten贸rio

Posted on

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;
}
Enter fullscreen mode Exit fullscreen mode

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;
}
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)