本文整理汇总了TypeScript中redux-saga/effects.cps函数的典型用法代码示例。如果您正苦于以下问题:TypeScript cps函数的具体用法?TypeScript cps怎么用?TypeScript cps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cps函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: testCps
function* testCps(): SagaIterator {
// typings:expect-error
yield cps((a: number) => {});
yield cps((cb) => {cb(null, 1)});
// typings:expect-error
yield cps<string>((cb) => {cb(null, 1)});
yield cps<number>((cb) => {cb(null, 1)});
yield cps((cb) => {cb.cancel = () => {}});
// typings:expect-error
yield cps((a: 'a', cb) => {});
// typings:expect-error
yield cps((a: 'a', cb) => {}, 1);
yield cps((a: 'a', cb) => {}, 'a');
// typings:expect-error
yield cps((a: 'a', b: 'b', cb) => {}, 'a');
// typings:expect-error
yield cps((a: 'a', b: 'b', cb) => {}, 'a', 1);
// typings:expect-error
yield cps((a: 'a', b: 'b', cb) => {}, 1, 'b');
yield cps((a: 'a', b: 'b', cb) => {}, 'a', 'b');
// typings:expect-error
yield cps(
(a: 'a', b: 'b', c: 'c', d: 'd', cb) => {},
1, 'b', 'c', 'd'
);
yield cps(
(a: 'a', b: 'b', c: 'c', d: 'd', cb) => {cb(null, 1)},
'a', 'b', 'c', 'd'
);
yield cps<number, 'a', 'b', 'c', 'd'>(
(a: 'a', b: 'b', c: 'c', d: 'd', cb) => {cb(null, 1)},
'a', 'b', 'c', 'd'
);
// typings:expect-error
yield cps(
(a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb) => {},
1, 'b', 'c', 'd', 'e', 'f'
);
yield cps(
(a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb) => {cb(null, 1)},
'a', 'b', 'c', 'd', 'e', 'f'
);
yield cps<number, 'a', 'b', 'c', 'd', 'e'>(
(a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb) => {cb(null, 1)},
'a', 'b', 'c', 'd', 'e', 'f'
);
const obj = {
foo: 'bar',
getFoo(arg: string, cb: (error: any, result: string) => void) {
cb(null, this.foo);
},
};
// typings:expect-error
yield cps([obj, obj.foo]);
// typings:expect-error
yield cps([obj, obj.getFoo]);
// typings:expect-error
yield cps([obj, obj.getFoo], 1);
yield cps([obj, obj.getFoo], 'bar');
yield cps<string, string>([obj, obj.getFoo], 'bar');
// typings:expect-error
yield cps([obj, 'foo']);
// typings:expect-error
yield cps([obj, 'getFoo']);
// typings:expect-error
yield cps([obj, 'getFoo'], 1);
yield cps([obj, 'getFoo'], 'bar');
yield cps<typeof obj, 'getFoo', string, string>([obj, 'getFoo'], 'bar');
// typings:expect-error
yield cps({context: obj, fn: obj.foo});
// typings:expect-error
yield cps({context: obj, fn: obj.getFoo});
// typings:expect-error
yield cps({context: obj, fn: obj.getFoo}, 1);
yield cps<string, string>({context: obj, fn: obj.getFoo}, 'bar');
// typings:expect-error
yield cps({context: obj, fn: 'foo'});
// typings:expect-error
yield cps({context: obj, fn: 'getFoo'});
// typings:expect-error
yield cps({context: obj, fn: 'getFoo'}, 1);
yield cps({context: obj, fn: 'getFoo'}, 'bar');
yield cps<typeof obj, 'getFoo', string, string>({context: obj, fn: 'getFoo'}, 'bar');
}
示例2: testCps
function* testCps(): SagaIterator {
type Cb<R> = (error: any, result: R) => void
// typings:expect-error
yield cps((a: number) => {})
yield cps(cb => {
cb(null, 1)
})
yield cps((cb: Cb<number>) => {
cb(null, 1)
})
// typings:expect-error
yield cps<(cb: Cb<string>) => void>(cb => {
cb(null, 1)
})
yield cps<(cb: Cb<number>) => void>(cb => {
cb(null, 1)
})
yield cps(cb => {
cb.cancel = () => {}
})
// typings:expect-error
yield cps((a: 'a', cb: Cb<number>) => {})
// typings:expect-error
yield cps((a: 'a', cb: Cb<number>) => {}, 1)
yield cps((a: 'a', cb: Cb<number>) => {}, 'a')
// typings:expect-error
yield cps((a: 'a', b: 'b', cb) => {}, 'a')
// typings:expect-error
yield cps((a: 'a', b: 'b', cb) => {}, 'a', 1)
// typings:expect-error
yield cps((a: 'a', b: 'b', cb: Cb<number>) => {}, 1, 'b')
yield cps((a: 'a', b: 'b', cb: Cb<number>) => {}, 'a', 'b')
// typings:expect-error
yield cps((a: 'a', b: 'b', c: 'c', d: 'd', cb: Cb<number>) => {}, 1, 'b', 'c', 'd')
yield cps(
(a: 'a', b: 'b', c: 'c', d: 'd', cb: Cb<number>) => {
cb(null, 1)
},
'a',
'b',
'c',
'd',
)
yield cps<(a: 'a', b: 'b', c: 'c', d: 'd', cb: Cb<number>) => void>(
(a: 'a', b: 'b', c: 'c', d: 'd', cb: Cb<number>) => {
cb(null, 1)
},
'a',
'b',
'c',
'd',
)
// typings:expect-error
yield cps((a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb: Cb<number>) => {}, 1, 'b', 'c', 'd', 'e', 'f')
yield cps(
(a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb: Cb<number>) => {
cb(null, 1)
},
'a',
'b',
'c',
'd',
'e',
'f',
)
yield cps<(a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb: Cb<number>) => void>(
(a: 'a', b: 'b', c: 'c', d: 'd', e: 'e', f: 'f', cb: Cb<number>) => {
cb(null, 1)
},
'a',
'b',
'c',
'd',
'e',
'f',
)
const obj = {
foo: 'bar',
getFoo(arg: string, cb: Cb<string>) {
cb(null, this.foo)
},
}
// typings:expect-error
yield cps([obj, obj.foo])
// typings:expect-error
yield cps([obj, obj.getFoo])
// typings:expect-error
yield cps([obj, obj.getFoo], 1)
//.........这里部分代码省略.........