How to use the tsd.expectError function in tsd

To help you get started, we’ve selected a few tsd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sindresorhus / type-fest / test-d / partial-deep.ts View on Github external
null: null,
		undefined: undefined, // eslint-disable-line object-shorthand
		map: new Map(),
		set: new Set(),
		array: ['foo'],
		tuple: ['foo'] as ['foo'],
		readonlyMap: new Map() as ReadonlyMap,
		readonlySet: new Set() as ReadonlySet,
		readonlyArray: ['foo'] as readonly string[],
		readonlyTuple: ['foo'] as const
	}
};

let partialDeepFoo: PartialDeep = foo;

expectError(expectType>(partialDeepFoo));
const partialDeepBar: PartialDeep = foo.bar;
expectType(partialDeepFoo.bar);
expectType<((_: string) => void) | undefined>(partialDeepFoo.bar!.function);
expectType(partialDeepFoo.bar!.object);
expectType(partialDeepFoo.bar!.string);
expectType(partialDeepFoo.bar!.number);
expectType(partialDeepFoo.bar!.boolean);
expectType
github dubzzz / fast-check / test / type / main.ts View on Github external
.afterEach(async () => 'anything')
);
expectType(
  fc
    .asyncProperty(fc.nat(), async () => {})
    .beforeEach(() => 123)
    .afterEach(() => 'anything')
);
expectError(fc.asyncProperty(fc.nat(), fc.string(), async (a: number, b: number) => {}));

// record arbitrary
expectType>(fc.record({ a: fc.nat(), b: fc.string() }));
expectType>(
  fc.record({ a: fc.nat(), b: fc.string() }, { withDeletedKeys: true })
);
expectError(fc.record({ a: 1 }));

// dictionary arbitrary
expectType>>(fc.dictionary(fc.string(), fc.nat()));
expectError(fc.dictionary(fc.nat(), fc.nat()));

// tuple arbitrary
expectType>(fc.tuple(fc.nat()));
expectType>(fc.tuple(fc.nat(), fc.string()));
expectError(fc.tuple(fc.nat(), ''));

// oneof arbitrary
expectType>(fc.oneof(fc.string(), fc.fullUnicodeString()));
expectType>(fc.oneof(fc.string() as fc.Arbitrary, fc.nat()));
expectError(fc.oneof(fc.string(), fc.nat())); // TODO Typings should be improved
expectError(fc.oneof(fc.string(), '1'));
github dubzzz / fast-check / test / type / main.ts View on Github external
expectType(fc.assert(fc.property(fc.nat(), () => {})));
expectType>(fc.assert(fc.asyncProperty(fc.nat(), async () => {})));

// property
expectType(fc.property(fc.nat(), a => {}) as fc.IProperty<[number]>);
expectType(fc.property(fc.nat(), fc.string(), (a, b) => {}) as fc.IProperty<[number, string]>);
expectType(
  fc.assert(
    fc
      .property(fc.nat(), () => {})
      .beforeEach(() => 123)
      .afterEach(() => 'anything')
  )
);
expectError(fc.property(fc.nat(), fc.string(), (a: number, b: number) => {}));
expectError(fc.assert(fc.property(fc.nat(), () => {}).beforeEach(async () => {})));
expectError(fc.assert(fc.property(fc.nat(), () => {}).afterEach(async () => {})));

// asyncProperty
expectType(fc.asyncProperty(fc.nat(), async a => {}) as fc.IAsyncProperty<[number]>);
expectType(fc.asyncProperty(fc.nat(), fc.string(), async (a, b) => {}) as fc.IAsyncProperty<[number, string]>);
expectType(
  fc
    .asyncProperty(fc.nat(), async () => {})
    .beforeEach(async () => 123)
    .afterEach(async () => 'anything')
);
expectType(
  fc
    .asyncProperty(fc.nat(), async () => {})
    .beforeEach(() => 123)
    .afterEach(() => 'anything')
github dubzzz / fast-check / test / type / main.ts View on Github external
.asyncProperty(fc.nat(), async () => {})
    .beforeEach(() => 123)
    .afterEach(() => 'anything')
);
expectError(fc.asyncProperty(fc.nat(), fc.string(), async (a: number, b: number) => {}));

// record arbitrary
expectType>(fc.record({ a: fc.nat(), b: fc.string() }));
expectType>(
  fc.record({ a: fc.nat(), b: fc.string() }, { withDeletedKeys: true })
);
expectError(fc.record({ a: 1 }));

// dictionary arbitrary
expectType>>(fc.dictionary(fc.string(), fc.nat()));
expectError(fc.dictionary(fc.nat(), fc.nat()));

// tuple arbitrary
expectType>(fc.tuple(fc.nat()));
expectType>(fc.tuple(fc.nat(), fc.string()));
expectError(fc.tuple(fc.nat(), ''));

// oneof arbitrary
expectType>(fc.oneof(fc.string(), fc.fullUnicodeString()));
expectType>(fc.oneof(fc.string() as fc.Arbitrary, fc.nat()));
expectError(fc.oneof(fc.string(), fc.nat())); // TODO Typings should be improved
expectError(fc.oneof(fc.string(), '1'));

// frequency arbitrary
expectType>(
  fc.frequency({ arbitrary: fc.string(), weight: 1 }, { arbitrary: fc.fullUnicodeString(), weight: 1 })
);
github dubzzz / fast-check / test / type / main.ts View on Github external
expectType>(fc.oneof(fc.string(), fc.fullUnicodeString()));
expectType>(fc.oneof(fc.string() as fc.Arbitrary, fc.nat()));
expectError(fc.oneof(fc.string(), fc.nat())); // TODO Typings should be improved
expectError(fc.oneof(fc.string(), '1'));

// frequency arbitrary
expectType>(
  fc.frequency({ arbitrary: fc.string(), weight: 1 }, { arbitrary: fc.fullUnicodeString(), weight: 1 })
);
expectType>(
  fc.frequency(
    { arbitrary: fc.string() as fc.Arbitrary, weight: 1 },
    { arbitrary: fc.nat(), weight: 1 }
  )
);
expectError(fc.frequency({ arbitrary: fc.string(), weight: 1 }, { arbitrary: fc.nat(), weight: 1 })); // TODO Typings should be improved
expectError(fc.frequency({ arbitrary: fc.string(), weight: 1 }, { arbitrary: '1', weight: 1 }));

// option arbitrary
expectType>(fc.option(fc.nat()));
expectType>(fc.option(fc.nat(), { nil: null }));
expectType>(fc.option(fc.nat(), { nil: 'custom_default' as const }));
expectError(fc.option(1));

// tie arbitrary
expectType<{}>(fc.letrec(tie => ({})));
expectType<{ a: fc.Arbitrary; b: fc.Arbitrary }>(
  fc.letrec(tie => ({
    a: fc.nat(),
    b: fc.string()
  }))
);
github sindresorhus / type-fest / test-d / readonly-deep.ts View on Github external
undefined: undefined, // eslint-disable-line object-shorthand
	map: new Map(),
	set: new Set(),
	array: ['foo'],
	tuple: ['foo'] as ['foo'],
	readonlyMap: new Map() as ReadonlyMap,
	readonlySet: new Set() as ReadonlySet,
	readonlyArray: ['foo'] as readonly string[],
	readonlyTuple: ['foo'] as const
};

const readonlyData: ReadonlyDeep = data;

readonlyData.fn('foo');

expectError(readonlyData.string = 'bar');
expectType<{readonly foo: string}>(readonlyData.object);
expectType(readonlyData.string);
expectType(readonlyData.number);
expectType(readonlyData.boolean);
expectType
github sindresorhus / hook-std / index.test-d.ts View on Github external
expectType((output: string, unhook: Unhook) => 'foo');
expectType((output: string, unhook: Unhook) => Buffer.from('foo'));
expectError((output: string, unhook: Unhook) => true);

expectType((output: string, unhook: Unhook) => undefined);
expectType((output: string, unhook: Unhook) => {});
expectType((output: string, unhook: Unhook) => true);
expectError((output: string, unhook: Unhook) => 'foo');
expectError((output: string, unhook: Unhook) =>
	Buffer.from('foo')
);

expectType(hookStd({once: true}, () => true));
expectError(hookStd({once: true}, () => 'foo'));
expectType(hookStd(() => true));
expectError(hookStd(() => 'foo'));
expectType(hookStd({silent: false}, () => 'foo'));
expectType(hookStd({silent: true}, () => true));
expectError(hookStd({silent: false}, () => true));
expectError(hookStd({silent: true}, () => 'foo'));
expectType(hookStd({streams: [process.stderr]}, () => true));
expectError(hookStd({streams: [process.stderr]}, () => 'foo'));
expectType(
	hookStd({silent: false, streams: [process.stderr]}, () => 'foo')
);
expectType(
	hookStd({silent: true, streams: [process.stderr]}, () => true)
);
expectError(hookStd({silent: false, streams: [process.stderr]}, () => true));
expectError(hookStd({silent: true, streams: [process.stderr]}, () => 'foo'));

expectType(hookStd.stdout({once: true}, () => true));
github aws / aws-xray-sdk-node / packages / core / test-d / index.test-d.ts View on Github external
expectType(AWSXRay.getNamespace().name);
expectType(AWSXRay.resolveSegment(segment));
expectType(AWSXRay.resolveSegment(undefined));
expectType(AWSXRay.resolveSegment(null));
expectType(AWSXRay.resolveSegment());
expectType(AWSXRay.getSegment());
expectType(AWSXRay.setSegment(segment));
expectType(AWSXRay.isAutomaticMode());
expectType(AWSXRay.enableAutomaticMode());
expectType(AWSXRay.enableManualMode());
expectType(AWSXRay.setContextMissingStrategy('LOG_ERROR'));
expectType(AWSXRay.setContextMissingStrategy('RUNTIME_ERROR'));
expectType(AWSXRay.setContextMissingStrategy(function() { }));
expectError(AWSXRay.setContextMissingStrategy('moop'));
expectError(AWSXRay.setContextMissingStrategy({}));

const rootId = '1-57fbe041-2c7ad569f5d6ff149137be86';
const parentId = 'f9c6e4f0b5116501';
new AWSXRay.Segment('foo', rootId);
new AWSXRay.Segment('foo', null, parentId);
new AWSXRay.Segment('foo');
expectType(segment.setUser('user'));
expectType(segment.setSDKData({ sdk_version: '1.0.0-beta' }));
expectType(segment.setMatchedSamplingRule('rule'));
expectType(segment.setServiceData({ version: '2.3.0', package: 'sample-app' }));
expectType(segment.addPluginData({ elastic_beanstalk: { environment: 'my_environment_name' } }));
const incomingMessage = new http.IncomingMessage(new Socket());
expectType(segment.addIncomingRequestData(new AWSXRay.middleware.IncomingRequestData(incomingMessage)));

function testSegmentLike(segmentLike: AWSXRay.Segment | AWSXRay.Subsegment) {
  expectType(segmentLike.addAnnotation('key', true));
github sindresorhus / type-fest / test-d / class.ts View on Github external
function fn2(Cls: Class): Foo {
	expectError(new Cls(1, ''));
	return new Cls(1, 2);
}
github anru / sprout / types / index.test-d.ts View on Github external
expectError(assoc(s, 0, 'string'))

function eatComplexStruct(s: ComplexStruct): ComplexStruct {
  return s
}

eatComplexStruct(merge(s[0], s[0]))
eatComplexStruct(deepMerge(s[0], s[0]))

eatComplexStruct(assoc(s[0], ['nested', 'step'], 5))

dissoc(s[0], 'name', 'nested')
dissoc(s, 0, 1, 2, 3)
dissoc(s, ['0', '1', '2'], 3)

expectError(eatComplexStruct(dissoc(s[0], 'name')))

expectError(eatComplexStruct(dissoc(s, 0)[0]))

update(s, [0, 'name'], (name: string, foo: string) => name + 'dfg', 1, 2, 3)[0]

update(s[0], 'name', (name: string) => name + 'hello')
expectError(update(s[0], 'name', (name: number) => name + 3))

tsd

Check TypeScript type definitions

MIT
Latest version published 4 months ago

Package Health Score

80 / 100
Full package analysis