• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript rsvp.reject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中rsvp.reject函数的典型用法代码示例。如果您正苦于以下问题:TypeScript reject函数的具体用法?TypeScript reject怎么用?TypeScript reject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了reject函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: testRethrow

function testRethrow() {
    RSVP.reject(new Error('all the badness'))
        .catch(RSVP.rethrow)
        .then(value => {
            assertType<void>(value);
        })
        .catch(reason => {
            if (reason instanceof Error) {
                console.log(reason);
            }
        });
}
开发者ID:Jeremy-F,项目名称:DefinitelyTyped,代码行数:12,代码来源:rsvp-tests.ts


示例2: testMap

function testMap() {
    RSVP.map([RSVP.resolve(1), RSVP.resolve(2)], item => item + 1, 'add one').then(results => {
        assertType<number[]>(results);
        assertType<{ length: 2 }>(results);
    });

    RSVP.map([RSVP.resolve('a string'), RSVP.resolve(112233)], String).then(results => {
        assertType<string[]>(results);
        assertType<{ length: 2 }>(results);
    });

    // This is the best we can do: we can't actually write the full type here,
    // which would be `assertType<never>(results)`, but TS can't infer that.
    RSVP.map([RSVP.reject('for any reason')], String).then(results => {
        assertType<{}>(results);
    });
}
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:17,代码来源:rsvp-tests.ts


示例3: testAllSettled

function testAllSettled() {
    const resolved1 = RSVP.resolve(1);
    const resolved2 = RSVP.resolve('wat');
    const rejected = RSVP.reject(new Error('oh teh noes'));
    const pending = new RSVP.Promise<{ neato: string }>((resolve, reject) => {
        if ('something') {
            resolve({ neato: 'yay' });
        } else {
            reject('nay');
        }
    });

    // Types flow into resolution properly
    RSVP.allSettled([resolved1, resolved2, rejected, pending]).then(states => {
        assertType<RSVP.PromiseState<number>>(states[0]);
        assertType<RSVP.PromiseState<string>>(states[1]);
        assertType<RSVP.PromiseState<never>>(states[2]);
        assertType<RSVP.PromiseState<{ neato: string }>>(states[3]);
    });

    // Switching on state gives the correctly available items.
    RSVP.allSettled([resolved1, resolved2, rejected, pending]).then(states => {
        states.forEach(element => {
            switch (element.state) {
                case RSVP.State.fulfilled:
                    assertType<RSVP.Resolved<typeof element.value>>(element);
                    break;

                case RSVP.State.rejected:
                    assertType<RSVP.Rejected<typeof element.reason>>(element);
                    break;

                case RSVP.State.pending:
                    assertType<RSVP.Pending>(element);
                    break;

                default:
                    // Someday maybe TS will have exhaustiveness checks.
                    break;
            }
        });
    });
}
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:43,代码来源:rsvp-tests.ts


示例4: testFilter

function testFilter() {
    RSVP.filter([RSVP.resolve(1), RSVP.resolve(2)], item => item > 1, 'over one').then(results => {
        assertType<number[]>(results);
    });

    RSVP.filter(
        [RSVP.resolve('a string'), RSVP.resolve(112233)],
        item => String(item).length < 10,
        'short string'
    ).then(results => {
        assertType<Array<string | number>>(results);
    });

    // This is the best we can do: we can't actually write the full type here,
    // which would be `assertType<never>(results)`, but TS can't infer that.
    const isString = (item: any): item is string => typeof item === 'string';
    RSVP.filter([RSVP.reject('for any reason')], isString).then(results => {
        assertType<{}>(results);
    });
}
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:20,代码来源:rsvp-tests.ts


示例5: testAll

function testAll() {
    const imported = all([]);
    const empty = RSVP.Promise.all([]);

    const everyPromise = RSVP.all([
        'string',
        RSVP.resolve(42),
        RSVP.resolve({ hash: 'with values' }),
    ]);

    assertType<RSVP.Promise<[string, number, { hash: string }]>>(everyPromise);

    const anyFailure = RSVP.all([12, 'strings', RSVP.reject('anywhere')]);
    assertType<RSVP.Promise<{}>>(anyFailure);

    let promise1 = RSVP.resolve(1);
    let promise2 = RSVP.resolve('2');
    let promise3 = RSVP.resolve({ key: 13 });
    RSVP.Promise.all([promise1, promise2, promise3], 'my label').then(function(array) {
        assertType<number>(array[0]);
        assertType<string>(array[1]);
        assertType<{ key: number }>(array[2]);
    });
}
开发者ID:Dru89,项目名称:DefinitelyTyped,代码行数:24,代码来源:rsvp-tests.ts


示例6: keepGoing

 function keepGoing() {
   return reject('NOPE');
 }
开发者ID:tildeio,项目名称:router.js,代码行数:3,代码来源:transition_state_test.ts


示例7: 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.reject函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript rsvp.resolve函数代码示例发布时间:2022-05-25
下一篇:
TypeScript rsvp.hash函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap