Created
April 17, 2018 14:32
-
-
Save kurogelee/8fc5c288d46661a90998d436be2caa5f to your computer and use it in GitHub Desktop.
TypeScriptでタプルへの型推論を行う方法 ref: https://qiita.com/kurogelee/items/12c45f9fb1615877a61f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tupleStrNum = ["X", 2]; // (string|number)[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { tuple } from "./util"; | |
const tupleStrNum = tuple("X", 2); // [string, number] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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