Skip to content

Instantly share code, notes, and snippets.

@kurogelee
Created April 17, 2018 14:32
Show Gist options
  • Save kurogelee/8fc5c288d46661a90998d436be2caa5f to your computer and use it in GitHub Desktop.
Save kurogelee/8fc5c288d46661a90998d436be2caa5f to your computer and use it in GitHub Desktop.
TypeScriptでタプルへの型推論を行う方法 ref: https://qiita.com/kurogelee/items/12c45f9fb1615877a61f
const tupleStrNum = ["X", 2]; // (string|number)[]
import { tuple } from "./util";
const tupleStrNum = tuple("X", 2); // [string, number]
export function tuple<T1, T2>(t1: T1, t2: T2): [T1, T2];
export function tuple<T1, T2, T3>(t1: T1, t2: T2, t3: T3): [T1, T2, T3];
export function tuple(...args: any[]) {
return args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment