Skip to content

Latest commit

 

History

History
37 lines (29 loc) · 743 Bytes

arguments-vs-object-style.md

File metadata and controls

37 lines (29 loc) · 743 Bytes

Arguments vs. Object style

Flag: --useOptions

There's no named parameter in JavaScript or TypeScript, because of that, we offer the flag --useOptions to generate code in two different styles.

Argument style:

const createUser = (name: string, password: string, type?: string, address?: string) => {
    // ...
};

// Usage
createUser('Jack', '123456', undefined, 'NY US');

Object style:

const createUser = ({ name, password, type, address }: {
    name: string,
    password: string,
    type?: string
    address?: string
}) => {
    // ...
};

// Usage
createUser({
    name: 'Jack',
    password: '123456',
    address: 'NY US'
});