Skip to content

Instantly share code, notes, and snippets.

@RubaXa
Last active December 20, 2019 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RubaXa/15c379a94864eb50dae97b69e3e40d80 to your computer and use it in GitHub Desktop.
Save RubaXa/15c379a94864eb50dae97b69e3e40d80 to your computer and use it in GitHub Desktop.
Tuple vs. <const>
let tuple = createTuple('foo', true, { bar: 2019 });
// 1. readonly [string, boolean, { bar: number }]
let constArray = <const>['foo', true, { bar: 2019 }];
// 2. readonly [string, boolean, { bar: number }]
let justArray = ['foo', true, { bar: 2019 }];
// 3. (string | boolean | { bar: number })
function createTuple<T extends any[]>(...args: T): Readonly<T> {
return args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment