Skip to content

Instantly share code, notes, and snippets.

@GermaVinsmoke
Created February 27, 2022 11:15
Show Gist options
  • Select an option

  • Save GermaVinsmoke/13acdbd00b03d01127a0bdb8d52fb74d to your computer and use it in GitHub Desktop.

Select an option

Save GermaVinsmoke/13acdbd00b03d01127a0bdb8d52fb74d to your computer and use it in GitHub Desktop.
File having code on how to create named parameters in Javascript/Typescript
/**
* Parameters needs to be passed in order πŸ˜£πŸ™„πŸ˜«
* Sometimes, by mistake can pass in wrong order 🀐
*/
const fun1 = (
one: string,
two: number,
three: boolean,
four: string,
five: number
) => {
console.log('Function without named parameters');
};
interface FunctionParameters {
one: string;
two: number;
three: boolean;
four: string;
five: number;
}
/**
* Can pass parameters in any order we want 😏
* No need to remember the order 😎
*/
const fun2 = ({ one, two, three, four, five }: FunctionParameters) => {
console.log('Function with named parameters');
};
fun1('test', 1, true, 'four', 5);
fun2({
five: 4,
three: false,
two: 1,
one: 'one',
four: 'test',
});
export { fun1, fun2 };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment