Skip to content

Instantly share code, notes, and snippets.

@tonkotsuboy
Last active February 9, 2018 02:18
Show Gist options
  • Save tonkotsuboy/c905deef18aa978ce5f10544290afdb4 to your computer and use it in GitHub Desktop.
Save tonkotsuboy/c905deef18aa978ce5f10544290afdb4 to your computer and use it in GitHub Desktop.
Promiseで複数のデータを流したい(TypeScript)
// FooData型とBarData型の値を流すことを考えてみる
interface FooData {
foo: string;
}
interface BarData {
bar: number;
}
// 3秒後に2つのデータを流す
new Promise<{ data1: FooData, data2: BarData }>(resolve => {
setTimeout(() => {
resolve({
data1: {foo: "boy"},
data2: {bar: 2}
});
}, 3000);
})
.then(result => console.log(result.data1.foo, result.data2.bar));
// boy, 2が出力される
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment