How to use tsd - 10 common examples

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 chalk / chalk / index.test-d.ts View on Github external
// - Chalk -
// -- Instance --
expectType(new chalk.Instance({level: 1}));

// -- Properties --
expectType(chalk.level);

// -- Template literal --
expectType(chalk``);
const name = 'John';
expectType(chalk`Hello {bold.red ${name}}`);
expectType(chalk`Works with numbers {bold.red ${1}}`);

// -- Color methods --
expectType(chalk.hex('#DEADED'));
expectType(chalk.keyword('orange'));
expectType(chalk.rgb(0, 0, 0));
expectType(chalk.hsl(0, 0, 0));
expectType(chalk.hsv(0, 0, 0));
expectType(chalk.hwb(0, 0, 0));
expectType(chalk.ansi(30));
expectType(chalk.ansi256(0));
expectType(chalk.bgHex('#DEADED'));
expectType(chalk.bgKeyword('orange'));
expectType(chalk.bgRgb(0, 0, 0));
expectType(chalk.bgHsl(0, 0, 0));
expectType(chalk.bgHsv(0, 0, 0));
expectType(chalk.bgHwb(0, 0, 0));
expectType(chalk.bgAnsi(30));
expectType(chalk.bgAnsi256(0));
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 angular-in-action / hello-world / gulpfile.js View on Github external
gulp.task('tsd', function() {
  var tsdAPI = tsd.getAPI('tsd.json');
  return tsdAPI.readConfig({}, true).then(function() {
    return tsdAPI.reinstall(
      tsd.Options.fromJSON({}) // https://github.com/DefinitelyTyped/tsd/blob/bb2dc91ad64f159298657805154259f9e68ea8a6/src/tsd/Options.ts
    ).then(function() {
      return tsdAPI.updateBundle(tsdAPI.context.config.bundle, true);
    });
  });
});
github aws / aws-xray-sdk-node / packages / core / test-d / index.test-d.ts View on Github external
expectType>(objects);
}

expectType(AWSXRay.captureHTTPs(http, true));
expectType(AWSXRay.captureHTTPs(https, true));

expectType(AWSXRay.captureHTTPsGlobal(http, true));
expectType(AWSXRay.captureHTTPsGlobal(https, true));

expectType(AWSXRay.capturePromise());
expectType(AWSXRay.capturePromise.patchThirdPartyPromise(Promise));

expectType<'error' | 'fault' | undefined>(AWSXRay.utils.getCauseTypeFromHttpStatus(200));
expectType(AWSXRay.utils.wildcardMatch('*', 'foo'));
expectType(AWSXRay.utils.LambdaUtils.validTraceData('moop'));
expectType(AWSXRay.utils.LambdaUtils.validTraceData());
expectType(AWSXRay.utils.LambdaUtils.populateTraceData(segment, 'moop'));
expectType<{ [key: string]: string }>(AWSXRay.utils.processTraceData());
expectType<{ [key: string]: string }>(AWSXRay.utils.processTraceData('Root=1-58ed6027-14afb2e09172c337713486c0;'));
const urlWithoutQuery: Omit = AWSXRay.utils.objectWithoutProperties(
  url.parse('url'), ['query'],
  true
);
expectError(urlWithoutQuery.query);

new AWSXRay.database.SqlData('databaseVer', 'driverVer', 'user', 'url', 'queryType');
const sqlData: AWSXRay.database.SqlData = new AWSXRay.database.SqlData();
expectType(sqlData.database_version);
expectType(sqlData.driver_version);
expectType(sqlData.preparation);
expectType(sqlData.url);
github sindresorhus / type-fest / test-d / package-json.ts View on Github external
import {expectType} from 'tsd';
import {PackageJson, LiteralUnion} from '..';

const packageJson: PackageJson = {};

expectType(packageJson.name);
expectType(packageJson.version);
expectType(packageJson.description);
expectType(packageJson.keywords);
expectType | undefined>(packageJson.homepage);
expectType(packageJson.bugs);
expectType(packageJson.license);
expectType | undefined>(packageJson.licenses);
expectType(packageJson.author);
expectType(packageJson.contributors);
expectType(packageJson.maintainers);
expectType(packageJson.files);
expectType(packageJson.main);
expectType(packageJson.bin);
expectType(packageJson.types);
expectType(packageJson.typings);
expectType(packageJson.man);
expectType(packageJson.directories);

tsd

Check TypeScript type definitions

MIT
Latest version published 3 months ago

Package Health Score

87 / 100
Full package analysis