当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript tsd.expectError函数代码示例

本文整理汇总了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));
开发者ID:sindresorhus,项目名称:negative-array,代码行数:9,代码来源:index.test-d.ts

示例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);
});
开发者ID:sindresorhus,项目名称:conf,代码行数:30,代码来源:index.test-d.ts

示例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(
开发者ID:sindresorhus,项目名称:first-chunk-stream,代码行数:31,代码来源:index.test-d.ts

示例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'));
开发者ID:sindresorhus,项目名称:anybar,代码行数:6,代码来源:index.test-d.ts

示例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);
开发者ID:sindresorhus,项目名称:builtin-modules,代码行数:9,代码来源:index.test-d.ts

示例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'}));
开发者ID:sindresorhus,项目名称:gravatar-url,代码行数:25,代码来源:index.test-d.ts

示例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}}`);
开发者ID:chalk,项目名称:chalk,代码行数:30,代码来源:index.test-d.ts

示例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'}));
开发者ID:sindresorhus,项目名称:dargs,代码行数:27,代码来源:index.test-d.ts

示例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(''));
开发者ID:sindresorhus,项目名称:html-tags,代码行数:14,代码来源:index.test-d.ts

示例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);
开发者ID:sindresorhus,项目名称:xdg-basedir,代码行数:15,代码来源:index.test-d.ts


注:本文中的tsd.expectError函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。