本文整理匯總了TypeScript中rsvp.Promise.reject方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Promise.reject方法的具體用法?TypeScript Promise.reject怎麽用?TypeScript Promise.reject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rsvp.Promise
的用法示例。
在下文中一共展示了Promise.reject方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: testReject
function testReject() {
assertType<RSVP.Promise<never>>(RSVP.reject());
assertType<RSVP.Promise<never>>(RSVP.reject('this is a string'));
RSVP.reject({ ok: false }).catch(reason => {
console.log(`${reason} could be anything`);
});
RSVP.reject({ ok: false }, 'some label').catch((reason: any) => reason.ok);
let promise = RSVP.Promise.reject(new Error('WHOOPS'));
}
示例2:
(() => {
if (err === null) {
return this.pageModel.ajax<any>(
'POST',
this.pageModel.createActionUrl('/subcorpus/subcorp', [['format', 'json']]),
args
);
} else {
return RSVP.Promise.reject(err);
}
})().then(
示例3: submit
submit():RSVP.Promise<any> {
const args = this.getSubmitArgs();
const err = this.validateForm(true);
if (err === null) {
return this.pageModel.ajax<any>(
'POST',
this.pageModel.createActionUrl('/subcorpus/subcorp', [['format', 'json']]),
args
);
} else {
return RSVP.Promise.reject(err);
}
}
示例4: Error
import RSVP from 'rsvp';
let promise1: RSVP.Promise<number, Error> = RSVP.Promise.resolve(1);
let promise1a: RSVP.Promise<number, Error> = RSVP.resolve(1);
let promise2: RSVP.Promise<number, Error> = RSVP.Promise.resolve(2);
let promise3: RSVP.Promise<number, Error> = RSVP.Promise.reject(new Error('3'));
let promise3a: RSVP.Promise<number, Error> = RSVP.reject(new Error('3'));
let promiseArray = [promise1, promise2, promise3];
let promiseHash = {
promiseA: promise1,
promiseB: promise2,
promiseC: promise3,
notAPromise: 4,
};
RSVP.Promise.all(promiseArray).then(arr => {}, err => {});
RSVP.all(promiseArray).then(arr => {}, err => {});
RSVP.Promise.race(promiseArray).then(arr => {}, err => {});
RSVP.race(promiseArray).then(arr => {}, err => {});
RSVP.allSettled(promiseArray).then(arr => {}, err => {});
let deferred = RSVP.defer();
deferred.resolve('Success');
deferred.promise.then(value => {});