本文整理汇总了TypeScript中tsd.expectError函数的典型用法代码示例。如果您正苦于以下问题:TypeScript expectError函数的具体用法?TypeScript expectError怎么用?TypeScript expectError使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了expectError函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: require
import {expectType, expectError} from 'tsd';
import negativeArray = require('.');
const readonlyArray = ['đ´', 'đ', 'đ'] as const;
const array = ['đ´', 'đ', 'đ'];
expectType<readonly string[]>(negativeArray(readonlyArray));
expectError(negativeArray(readonlyArray).push('đŚ'));
expectType<string[]>(negativeArray(array));
示例2: Buffer
});
new Conf<string>({configName: ''});
new Conf<string>({projectName: 'foo'});
new Conf<string>({cwd: ''});
new Conf<string>({encryptionKey: ''});
new Conf<string>({encryptionKey: new Buffer('')});
new Conf<string>({encryptionKey: new Uint8Array([1])});
new Conf<string>({encryptionKey: new DataView(new ArrayBuffer(2))});
new Conf<string>({fileExtension: '.foo'});
new Conf<string>({clearInvalidConfig: false});
new Conf<string>({serialize: value => 'foo'});
new Conf<string>({deserialize: string => ({})});
new Conf<string>({projectSuffix: 'foo'});
new Conf<string>({schema: {foo: {type: 'string'}}});
expectError(new Conf<string>({schema: {foo: {type: 'nope'}}}));
conf.set('foo', 'bar');
conf.set('hello', 1);
conf.set('unicorn', false);
expectType<string | number | boolean>(conf.get('foo'));
expectType<string | number | boolean>(conf.get('foo', 'bar'));
conf.delete('foo');
expectType<boolean>(conf.has('foo'));
conf.clear();
const off = conf.onDidChange('foo', (oldValue, newValue) => {
expectType<string | number | boolean | undefined>(oldValue);
expectType<string | number | boolean | undefined>(newValue);
});
示例3: require
/// <reference types="node"/>
import * as fs from 'fs';
import {Duplex} from 'stream';
import {expectType, expectError} from 'tsd';
import FirstChunkStream = require('.');
const options: FirstChunkStream.Options = {chunkLength: 1};
expectError(new FirstChunkStream());
expectError(new FirstChunkStream({}, () => {}));
const firstChunkStream = new FirstChunkStream(
{chunkLength: 7},
(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(
示例4: require
import {expectType, expectError} from 'tsd';
import anybar = require('.');
expectType<Promise<void>>(anybar('red'));
expectType<Promise<void>>(anybar('red', {port: 123}));
expectError(anybar('foo'));
示例5: require
import {expectType, expectError} from 'tsd';
import builtinModules = require('.');
import builtinModulesStatic = require ('./static');
expectType<readonly string[]>(builtinModules);
expectError<string[]>(builtinModules);
expectType<readonly string[]>(builtinModulesStatic);
expectError<string[]>(builtinModulesStatic);
示例6: require
import {expectType, expectError} from 'tsd';
import gravatarUrl = require('.');
const options: gravatarUrl.Options = {}; // Check interface export
expectType<string>(gravatarUrl('sindresorhus@gmail.com'));
expectType<string>(gravatarUrl('sindresorhus@gmail.com', {default: '404'}));
expectType<string>(gravatarUrl('sindresorhus@gmail.com', {default: 'blank'}));
expectType<string>(
gravatarUrl('sindresorhus@gmail.com', {default: 'identicon'})
);
expectType<string>(gravatarUrl('sindresorhus@gmail.com', {default: 'mm'}));
expectType<string>(
gravatarUrl('sindresorhus@gmail.com', {default: 'monsterid'})
);
expectType<string>(gravatarUrl('sindresorhus@gmail.com', {default: 'retro'}));
expectType<string>(gravatarUrl('sindresorhus@gmail.com', {default: 'wavatar'}));
expectType<string>(
gravatarUrl('sindresorhus@gmail.com', {default: 'https://example.com'})
);
expectType<string>(gravatarUrl('sindresorhus@gmail.com', {size: 200}));
expectType<string>(gravatarUrl('sindresorhus@gmail.com', {rating: 'g'}));
expectType<string>(gravatarUrl('sindresorhus@gmail.com', {rating: 'pg'}));
expectType<string>(gravatarUrl('sindresorhus@gmail.com', {rating: 'r'}));
expectType<string>(gravatarUrl('sindresorhus@gmail.com', {rating: 'x'}));
expectError(gravatarUrl('sindresorhus@gmail.com', {rating: 'foo'}));
示例7: expectError
// - Helpers -
type colorReturn = chalk.Chalk & {supportsColor?: never};
// - Level -
expectType<number>(chalk.Level.None);
expectType<number>(chalk.Level.Basic);
expectType<number>(chalk.Level.Ansi256);
expectType<number>(chalk.Level.TrueColor);
// - supportsColor -
expectType<boolean>(chalk.supportsColor.hasBasic);
expectType<boolean>(chalk.supportsColor.has256);
expectType<boolean>(chalk.supportsColor.has16m);
// -- `supportsColor` is not a member of the Chalk interface --
expectError(chalk.reset.supportsColor);
// - Chalk -
// -- Instance --
expectType<chalk.Chalk>(new chalk.Instance({level: 1}));
// -- Properties --
expectType<boolean>(chalk.enabled);
expectType<chalk.Level>(chalk.level);
// -- Template literal --
expectType<string>(chalk``);
const name = 'John';
expectType<string>(chalk`Hello {bold.red ${name}}`);
expectType<string>(chalk`Works with numbers {bold.red ${1}}`);
示例8: require
import {expectType, expectError} from 'tsd';
import dargs = require('.');
const input = {
_: ['some', 'option'],
foo: 'bar',
hello: true,
cake: false,
camelCase: 5,
multiple: ['value', 'value2'],
pieKind: 'cherry',
sad: ':('
};
const excludes = ['sad', /.*Kind$/];
const includes = ['camelCase', 'multiple', 'sad', /^pie.*/];
const aliases = {file: 'f'};
expectType<string[]>(dargs(input, {excludes}));
expectType<string[]>(dargs(input, {includes}));
expectType<string[]>(dargs(input, {aliases}));
expectType<string[]>(dargs(input, {useEquals: false}));
expectType<string[]>(dargs(input, {ignoreFalse: true}));
expectType<string[]>(dargs(input, {allowCamelCase: true}));
expectError(dargs({_: 'foo'}));
expectError(dargs({'--': 'foo'}));
示例9: require
import {expectType, expectError} from 'tsd';
import htmlTags = require('.');
import voidHtmlTags = require('./void');
import htmlTagsJson = require('./html-tags.json');
import voidHtmlTagsJson = require('./html-tags-void.json');
expectType<readonly string[]>(htmlTags);
expectError(htmlTags.push(''));
expectType<readonly string[]>(voidHtmlTags);
expectError(voidHtmlTags.push(''));
expectType<readonly string[]>(htmlTagsJson);
expectError(htmlTagsJson.push(''));
expectType<readonly string[]>(voidHtmlTagsJson);
expectError(voidHtmlTagsJson.push(''));
示例10: require
import {expectType, expectError} from 'tsd';
import xdgBasedir = require('.');
expectType<string | undefined>(xdgBasedir.data);
expectError<string>(xdgBasedir.data);
expectType<string | undefined>(xdgBasedir.config);
expectError<string>(xdgBasedir.config);
expectType<string | undefined>(xdgBasedir.cache);
expectError<string>(xdgBasedir.cache);
expectType<string | undefined>(xdgBasedir.runtime);
expectError<string>(xdgBasedir.runtime);
expectType<readonly string[]>(xdgBasedir.configDirs);
expectError<string[]>(xdgBasedir.configDirs);
expectType<readonly string[]>(xdgBasedir.dataDirs);
expectError<string[]>(xdgBasedir.dataDirs);