當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。