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.

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<string, string>(),
		set: new Set<string>(),
		array: ['foo'],
		tuple: ['foo'] as ['foo'],
		readonlyMap: new Map<string, string>() as ReadonlyMap<string, string>,
		readonlySet: new Set<string>() as ReadonlySet<string>,
		readonlyArray: ['foo'] as readonly string[],
		readonlyTuple: ['foo'] as const
	}
};

let partialDeepFoo: PartialDeep<typeof foo> = foo;

expectError(expectType<Partial<typeof foo>>(partialDeepFoo));
const partialDeepBar: PartialDeep<typeof foo.bar> = foo.bar;
expectType<typeof partialDeepBar | undefined>(partialDeepFoo.bar);
expectType<((_: string) => void) | undefined>(partialDeepFoo.bar!.function);
expectType<object | undefined>(partialDeepFoo.bar!.object);
expectType<string | undefined>(partialDeepFoo.bar!.string);
expectType<number | undefined>(partialDeepFoo.bar!.number);
expectType<boolean | undefined>(partialDeepFoo.bar!.boolean);
expectType<symbol | undefined>(partialDeepFoo.bar!.symbol);
expectType<null | undefined>(partialDeepFoo.bar!.null);
expectType<undefined>(partialDeepFoo.bar!.undefined);
expectType<Map<string | undefined, string | undefined> | undefined>(partialDeepFoo.bar!.map);
expectType<Set<string | undefined> | undefined>(partialDeepFoo.bar!.set);
expectType<Array<string | undefined> | undefined>(partialDeepFoo.bar!.array);
expectType<['foo'?] | undefined>(partialDeepFoo.bar!.tuple);
expectType<ReadonlyMap<string | undefined, string | undefined> | undefined>(partialDeepFoo.bar!.readonlyMap);
expectType<ReadonlySet<string | undefined> | undefined>(partialDeepFoo.bar!.readonlySet);
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.Arbitrary<{ a: number; b: string }>>(fc.record({ a: fc.nat(), b: fc.string() }));
expectType<fc.Arbitrary<{ a?: number; b?: string }>>(
  fc.record({ a: fc.nat(), b: fc.string() }, { withDeletedKeys: true })
);
expectError(fc.record({ a: 1 }));

// dictionary arbitrary
expectType<fc.Arbitrary<Record<string, number>>>(fc.dictionary(fc.string(), fc.nat()));
expectError(fc.dictionary(fc.nat(), fc.nat()));

// tuple arbitrary
expectType<fc.Arbitrary<[number]>>(fc.tuple(fc.nat()));
expectType<fc.Arbitrary<[number, string]>>(fc.tuple(fc.nat(), fc.string()));
expectError(fc.tuple(fc.nat(), ''));

// oneof arbitrary
expectType<fc.Arbitrary<string>>(fc.oneof(fc.string(), fc.fullUnicodeString()));
expectType<fc.Arbitrary<number | string>>(fc.oneof(fc.string() as fc.Arbitrary<number | string>, 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<void>(fc.assert(fc.property(fc.nat(), () => {})));
expectType<Promise<void>>(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.Arbitrary<{ a: number; b: string }>>(fc.record({ a: fc.nat(), b: fc.string() }));
expectType<fc.Arbitrary<{ a?: number; b?: string }>>(
  fc.record({ a: fc.nat(), b: fc.string() }, { withDeletedKeys: true })
);
expectError(fc.record({ a: 1 }));

// dictionary arbitrary
expectType<fc.Arbitrary<Record<string, number>>>(fc.dictionary(fc.string(), fc.nat()));
expectError(fc.dictionary(fc.nat(), fc.nat()));

// tuple arbitrary
expectType<fc.Arbitrary<[number]>>(fc.tuple(fc.nat()));
expectType<fc.Arbitrary<[number, string]>>(fc.tuple(fc.nat(), fc.string()));
expectError(fc.tuple(fc.nat(), ''));

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

// frequency arbitrary
expectType<fc.Arbitrary<string>>(
  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.Arbitrary<string>>(fc.oneof(fc.string(), fc.fullUnicodeString()));
expectType<fc.Arbitrary<number | string>>(fc.oneof(fc.string() as fc.Arbitrary<number | string>, fc.nat()));
expectError(fc.oneof(fc.string(), fc.nat())); // TODO Typings should be improved
expectError(fc.oneof(fc.string(), '1'));

// frequency arbitrary
expectType<fc.Arbitrary<string>>(
  fc.frequency({ arbitrary: fc.string(), weight: 1 }, { arbitrary: fc.fullUnicodeString(), weight: 1 })
);
expectType<fc.Arbitrary<number | string>>(
  fc.frequency(
    { arbitrary: fc.string() as fc.Arbitrary<number | string>, 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.Arbitrary<number | null>>(fc.option(fc.nat()));
expectType<fc.Arbitrary<number | null>>(fc.option(fc.nat(), { nil: null }));
expectType<fc.Arbitrary<number | 'custom_default'>>(fc.option(fc.nat(), { nil: 'custom_default' as const }));
expectError(fc.option(1));

// tie arbitrary
expectType<{}>(fc.letrec(tie => ({})));
expectType<{ a: fc.Arbitrary<number>; b: fc.Arbitrary<string> }>(
  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<string, string>(),
	set: new Set<string>(),
	array: ['foo'],
	tuple: ['foo'] as ['foo'],
	readonlyMap: new Map<string, string>() as ReadonlyMap<string, string>,
	readonlySet: new Set<string>() as ReadonlySet<string>,
	readonlyArray: ['foo'] as readonly string[],
	readonlyTuple: ['foo'] as const
};

const readonlyData: ReadonlyDeep<typeof data> = data;

readonlyData.fn('foo');

expectError(readonlyData.string = 'bar');
expectType<{readonly foo: string}>(readonlyData.object);
expectType<string>(readonlyData.string);
expectType<number>(readonlyData.number);
expectType<boolean>(readonlyData.boolean);
expectType<symbol>(readonlyData.symbol);
expectType<null>(readonlyData.null);
expectType<undefined>(readonlyData.undefined);
expectType<ReadonlyMap<string, string>>(readonlyData.map);
expectType<ReadonlySet<string>>(readonlyData.set);
expectType<readonly string[]>(readonlyData.array);
expectType<readonly ['foo']>(readonlyData.tuple);
expectType<ReadonlyMap<string, string>>(readonlyData.readonlyMap);
expectType<ReadonlySet<string>>(readonlyData.readonlySet);
expectType<readonly string[]>(readonlyData.readonlyArray);
expectType<readonly ['foo']>(readonlyData.readonlyTuple);
github sindresorhus / hook-std / index.test-d.ts View on Github external
expectType<Transform>((output: string, unhook: Unhook) => 'foo');
expectType<Transform>((output: string, unhook: Unhook) => Buffer.from('foo'));
expectError<Transform>((output: string, unhook: Unhook) => true);

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

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

expectType<HookPromise>(hookStd.stdout({once: true}, () => true));
github aws / aws-xray-sdk-node / packages / core / test-d / index.test-d.ts View on Github external
expectType<string>(AWSXRay.getNamespace().name);
expectType<AWSXRay.Segment | AWSXRay.Subsegment | undefined>(AWSXRay.resolveSegment(segment));
expectType<AWSXRay.Segment | AWSXRay.Subsegment | undefined>(AWSXRay.resolveSegment(undefined));
expectType<AWSXRay.Segment | AWSXRay.Subsegment | undefined>(AWSXRay.resolveSegment(null));
expectType<AWSXRay.Segment | AWSXRay.Subsegment | undefined>(AWSXRay.resolveSegment());
expectType<AWSXRay.Segment | AWSXRay.Subsegment | undefined>(AWSXRay.getSegment());
expectType<void>(AWSXRay.setSegment(segment));
expectType<boolean>(AWSXRay.isAutomaticMode());
expectType<void>(AWSXRay.enableAutomaticMode());
expectType<void>(AWSXRay.enableManualMode());
expectType<void>(AWSXRay.setContextMissingStrategy('LOG_ERROR'));
expectType<void>(AWSXRay.setContextMissingStrategy('RUNTIME_ERROR'));
expectType<void>(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<void>(segment.setUser('user'));
expectType<void>(segment.setSDKData({ sdk_version: '1.0.0-beta' }));
expectType<void>(segment.setMatchedSamplingRule('rule'));
expectType<void>(segment.setServiceData({ version: '2.3.0', package: 'sample-app' }));
expectType<void>(segment.addPluginData({ elastic_beanstalk: { environment: 'my_environment_name' } }));
const incomingMessage = new http.IncomingMessage(new Socket());
expectType<void>(segment.addIncomingRequestData(new AWSXRay.middleware.IncomingRequestData(incomingMessage)));

function testSegmentLike(segmentLike: AWSXRay.Segment | AWSXRay.Subsegment) {
  expectType<void>(segmentLike.addAnnotation('key', true));
github sindresorhus / type-fest / test-d / class.ts View on Github external
function fn2(Cls: Class<Foo, [number, number]>): 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 12 days ago

Package Health Score

86 / 100
Full package analysis

Similar packages