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


TypeScript tcomb.interface函數代碼示例

本文整理匯總了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;未經允許,請勿轉載。