當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Promise.reject方法代碼示例

本文整理匯總了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'));
}
開發者ID:Dru89,項目名稱:DefinitelyTyped,代碼行數:11,代碼來源:rsvp-tests.ts

示例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(
開發者ID:czcorpus,項目名稱:kontext,代碼行數:12,代碼來源:withinForm.ts

示例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);
        }
    }
開發者ID:czcorpus,項目名稱:kontext,代碼行數:14,代碼來源:form.ts

示例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 => {});
開發者ID:DxCx,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:rsvp-tests.ts


注:本文中的rsvp.Promise.reject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。