Last active
February 9, 2018 02:18
-
-
Save tonkotsuboy/c905deef18aa978ce5f10544290afdb4 to your computer and use it in GitHub Desktop.
Promiseで複数のデータを流したい(TypeScript)
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
// 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