跳至主要内容

[TS] JavaScript Snippets of TypeScript

Promise

Promise

const fetchResidentsInfo = (): Promise<ResidentInfo[]> => {
return new Promise((resolve, reject) => {
resolve(MOCKUP.residentsInfo);
});
};

Promise.all

How to use Promise.all() with Typescript @ StackOverflow

let foo: [Promise<Aurelia>, Promise<void>] = [aurelia.start(), entityManagerProvider.initialize()];
Promise.all(foo).then((results: any[]) => {
let aurelia: any = results[0];
aurelia.setRoot();
});
Promise.all<Aurelia, void>([
aurelia.start(),
entityManagerProvider.initialize(),
]).then(([aurelia]) => aurelia.setRoot());

Async

const fetchData = async (): Promise<void> => {
/* ... */
};