本文整理汇总了TypeScript中tcomb.interface函数的典型用法代码示例。如果您正苦于以下问题:TypeScript interface函数的具体用法?TypeScript interface怎么用?TypeScript interface使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了interface函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: describe
describe('connect', () => {
type ST = { view: string };
const { connect } = stateInit(t.interface<ST>({ view: t.String }, { strict: true }));
it('should throw if select is invalid', () => {
expect(() => connect(['bar'])).toThrowError('bar is not defined in state');
});
});
开发者ID:buildo,项目名称:state,代码行数:8,代码来源:connect.test.ts
示例2: describe
describe('transition', () => {
type ST = { view: string };
const stateType = t.interface<ST>({ view: t.String }, { strict: true });
it('should do nothing if there is no state diff', () => {
const { transition, states } = prepareTransition({ stateType, initialState: { view: 'bar' } });
transition({ view: 'bar' });
expect(states).toEqual([{ view: 'bar' }]);
});
it('should push synchronously if there is state diff', () => {
const { transition, states } = prepareTransition({ stateType, initialState: { view: 'bar' } });
transition({ view: 'baz' });
expect(states).toEqual([{ view: 'bar' }, { view: 'baz' }]);
});
it('should throw if it evaluates to a state with a key of invalid type', () => {
const { transition } = prepareTransition({ stateType, initialState: { view: 'bar' } });
const invalidTransition = () => {
transition({ view: 2 });
};
expect(invalidTransition).toThrow();
});
it('should throw if it evaluates to a state with an extraneous key', () => {
const { transition } = prepareTransition({ stateType, initialState: { view: 'bar' } });
const invalidTransition = () => {
transition({ view: 'bar', bar: 'foo' });
};
expect(invalidTransition).toThrow();
});
});
开发者ID:buildo,项目名称:state,代码行数:39,代码来源:transition.test.ts
示例3: it
import { parse as _parse, stringify as _stringify } from '../src/parser';
import * as t from 'tcomb';
type S = {
view: string;
numb: number;
bool: boolean;
optNumb?: number;
optBool?: boolean;
};
const ST = t.interface<S>({
view: t.String,
numb: t.Number,
bool: t.Boolean,
optNumb: t.maybe(t.Number),
optBool: t.maybe(t.Boolean)
});
const parse = _parse(ST);
const stringify = _stringify(ST);
describe('parse', () => {
it('should parse numbers', () => {
expect(parse({ view: 'foo', numb: '4' })).toMatchSnapshot();
});
it('should parse optional numbers', () => {
expect(parse({ view: 'foo', optNumb: '4' })).toMatchSnapshot();
});
it('should parse booleans', () => {
expect(parse({ view: 'foo', bool: 'true' })).toMatchSnapshot();
});
it('should parse optional booleans', () => {
开发者ID:buildo,项目名称:state,代码行数:31,代码来源:parser.test.ts
示例4: it
it('should throw if initialState is invalid', () => {
type StateType = { view: string };
const stateType = t.interface<StateType>({ view: t.String }, { name: 'AppState', strict: true });
const { run } = stateInit(stateType);
expect(() => run({ initialState: { foo: 1 } })).toThrow();
});
开发者ID:buildo,项目名称:state,代码行数:6,代码来源:run.test.ts
示例5: expect
expect(() => stateInit(t.interface({}, { strict: false }))).toThrowError(
开发者ID:buildo,项目名称:state,代码行数:1,代码来源:index.test.ts
注:本文中的tcomb.interface函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论