本文整理汇总了TypeScript中tsd.expectType函数的典型用法代码示例。如果您正苦于以下问题:TypeScript expectType函数的具体用法?TypeScript expectType怎么用?TypeScript expectType使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了expectType函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
mapValues: ({ header, index, value }) => {
expectType<string>(header);
expectType<number>(index);
expectType<any>(value);
return value.toLowerCase();
},
示例2: constructor
constructor(props: object) {
super(props);
expectType<Bar>(autoBind.react(this));
expectType<Bar>(autoBind.react(this, {include: ['foo', /bar/]}));
expectType<Bar>(autoBind.react(this, {exclude: ['foo', /bar/]}));
}
示例3: cpy
cpy('foo.js', 'destination').on('progress', progress => {
expectType<ProgressData>(progress);
expectType<number>(progress.completedFiles);
expectType<number>(progress.totalFiles);
expectType<number>(progress.completedSize);
expectType<number>(progress.percent);
})
示例4:
data => {
expectType<ProgressData>(data);
expectType<string>(data.src);
expectType<string>(data.dest);
expectType<number>(data.size);
expectType<number>(data.written);
expectType<number>(data.percent);
}
示例5:
(error, chunk, encoding, callback) => {
expectType<Error | null>(error);
expectType<Buffer>(chunk);
expectType<string>(encoding);
expectType<
(
error?: Error | null,
buffer?: string | Buffer | Uint8Array,
encoding?: string
) => void
>(callback);
callback();
callback(null);
callback(error);
callback(null, chunk.toString(encoding).toUpperCase());
callback(null, Buffer.from(chunk.toString(encoding).toUpperCase()));
callback(
null,
new Uint8Array(Buffer.from(chunk.toString(encoding).toUpperCase()))
);
callback(null, chunk.toString(encoding).toUpperCase(), 'utf8');
callback(null, chunk.toString(encoding).toUpperCase(), encoding);
}
示例6: require
import {expectType} from 'tsd';
import pathExists = require('.');
expectType<Promise<boolean>>(pathExists('foo.ts'));
expectType<boolean>(pathExists.sync('foo.ts'));
示例7: require
import {expectType} from 'tsd';
import imageType = require('.');
import {ImageTypeResult, ImageType} from '.';
imageType(new Buffer([0xff, 0xd8, 0xff]));
imageType(new Uint8Array([0xff, 0xd8, 0xff]));
expectType<ImageTypeResult | null>(imageType(new Buffer([0xff, 0xd8, 0xff])));
expectType<ImageTypeResult | null>(
imageType(new Uint8Array([0xff, 0xd8, 0xff]))
);
const result = imageType(new Buffer([0xff, 0xd8, 0xff]));
if (result != null) {
expectType<ImageType>(result.ext);
expectType<string>(result.mime);
}
expectType<number>(imageType.minimumBytes);
示例8: require
import {expectType} from 'tsd';
import arrayUniq = require('.');
expectType<number[]>(arrayUniq([1, 2, 3]));
示例9: require
import {expectType} from 'tsd';
import mapObject = require('.');
const options: mapObject.Options = {};
const newObject = mapObject({foo: 'bar'}, (key, value) => [value, key]);
expectType<{[key: string]: 'foo'}>(newObject);
expectType<'foo'>(newObject.bar);
const object = mapObject({foo: 'bar'}, (key, value) => [value, key], {
target: {baz: 'baz'}
});
expectType<{baz: string} & {[x: string]: 'foo'}>(object);
expectType<'foo'>(object.bar);
expectType<string>(object.baz);
const object1 = mapObject({foo: 'bar'}, (key, value) => [value, key], {
target: {baz: 'baz'},
deep: false
});
expectType<{baz: string} & {[x: string]: 'foo'}>(object1);
expectType<'foo'>(object1.bar);
expectType<string>(object1.baz);
const object2 = mapObject({foo: 'bar'}, (key, value) => [value, key], {
deep: true
});
expectType<{[key: string]: unknown}>(object2);
const object3 = mapObject({foo: 'bar'}, (key, value) => [value, key], {
deep: true,
target: {bar: 'baz' as const}
示例10: require
import {expectType} from 'tsd';
import superb = require('.');
expectType<readonly string[]>(superb.all);
expectType<string>(superb.random());