Require TypeScript 4.2 and Node.js 12.20

This commit is contained in:
Sindre Sorhus 2021-08-06 01:13:47 +02:00
parent f4144d83c4
commit a55ebee883
86 changed files with 218 additions and 255 deletions

View File

@ -10,12 +10,12 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
@ -28,13 +28,11 @@ jobs:
matrix:
typescript-version:
- 'latest'
- '^4.1.0'
- '~4.0.0'
- '^3.9.0'
- '~3.4.0'
- '^4.3.0'
- '4.2.0'
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 14
- run: npm install

42
base.d.ts vendored
View File

@ -1,42 +0,0 @@
// Types that are compatible with all supported TypeScript versions.
// It's shared between all TypeScript version-specific definitions.
// Basic
export * from './source/primitive';
export * from './source/typed-array';
export * from './source/basic';
export * from './source/observable-like';
// Utilities
export {Except} from './source/except';
export {Mutable} from './source/mutable';
export {Merge} from './source/merge';
export {MergeExclusive} from './source/merge-exclusive';
export {RequireAtLeastOne} from './source/require-at-least-one';
export {RequireExactlyOne} from './source/require-exactly-one';
export {PartialDeep} from './source/partial-deep';
export {ReadonlyDeep} from './source/readonly-deep';
export {LiteralUnion} from './source/literal-union';
export {Promisable} from './source/promisable';
export {Opaque} from './source/opaque';
export {SetOptional} from './source/set-optional';
export {SetRequired} from './source/set-required';
export {ValueOf} from './source/value-of';
export {PromiseValue} from './source/promise-value';
export {AsyncReturnType} from './source/async-return-type';
export {ConditionalExcept} from './source/conditional-except';
export {ConditionalKeys} from './source/conditional-keys';
export {ConditionalPick} from './source/conditional-pick';
export {UnionToIntersection} from './source/union-to-intersection';
export {Stringified} from './source/stringified';
export {FixedLengthArray} from './source/fixed-length-array';
export {IterableElement} from './source/iterable-element';
export {Entry} from './source/entry';
export {Entries} from './source/entries';
export {SetReturnType} from './source/set-return-type';
export {Asyncify} from './source/asyncify';
export {Simplify} from './source/simplify';
// Miscellaneous
export {PackageJson} from './source/package-json';
export {TsConfigJson} from './source/tsconfig-json';

64
index.d.ts vendored
View File

@ -1,2 +1,62 @@
// These are all the basic types that's compatible with all supported TypeScript versions.
export * from './base';
// Basic
export * from './source/primitive';
export * from './source/typed-array';
export * from './source/basic';
export * from './source/observable-like';
// Utilities
export {Except} from './source/except';
export {Mutable} from './source/mutable';
export {Merge} from './source/merge';
export {MergeExclusive} from './source/merge-exclusive';
export {RequireAtLeastOne} from './source/require-at-least-one';
export {RequireExactlyOne} from './source/require-exactly-one';
export {PartialDeep} from './source/partial-deep';
export {ReadonlyDeep} from './source/readonly-deep';
export {LiteralUnion} from './source/literal-union';
export {Promisable} from './source/promisable';
export {Opaque} from './source/opaque';
export {SetOptional} from './source/set-optional';
export {SetRequired} from './source/set-required';
export {ValueOf} from './source/value-of';
export {PromiseValue} from './source/promise-value';
export {AsyncReturnType} from './source/async-return-type';
export {ConditionalExcept} from './source/conditional-except';
export {ConditionalKeys} from './source/conditional-keys';
export {ConditionalPick} from './source/conditional-pick';
export {UnionToIntersection} from './source/union-to-intersection';
export {Stringified} from './source/stringified';
export {FixedLengthArray} from './source/fixed-length-array';
export {IterableElement} from './source/iterable-element';
export {Entry} from './source/entry';
export {Entries} from './source/entries';
export {SetReturnType} from './source/set-return-type';
export {Asyncify} from './source/asyncify';
export {Simplify} from './source/simplify';
// Template literal types
export {CamelCase} from './source/camel-case';
export {CamelCasedProperties} from './source/camel-cased-properties';
export {CamelCasedPropertiesDeep} from './source/camel-cased-properties-deep';
export {KebabCase} from './source/kebab-case';
export {KebabCasedProperties} from './source/kebab-cased-properties';
export {KebabCasedPropertiesDeep} from './source/kebab-cased-properties-deep';
export {PascalCase} from './source/pascal-case';
export {PascalCasedProperties} from './source/pascal-cased-properties';
export {PascalCasedPropertiesDeep} from './source/pascal-cased-properties-deep';
export {SnakeCase} from './source/snake-case';
export {SnakeCasedProperties} from './source/snake-cased-properties';
export {SnakeCasedPropertiesDeep} from './source/snake-cased-properties-deep';
export {ScreamingSnakeCase} from './source/screaming-snake-case';
export {DelimiterCase} from './source/delimiter-case';
export {DelimiterCasedProperties} from './source/delimiter-cased-properties';
export {DelimiterCasedPropertiesDeep} from './source/delimiter-cased-properties-deep';
export {Split} from './source/split';
export {Trim} from './source/trim';
export {Includes} from './source/includes';
export {Get} from './source/get';
export {LastArrayElement} from './source/last-array-element';
// Miscellaneous
export {PackageJson} from './source/package-json';
export {TsConfigJson} from './source/tsconfig-json';

View File

@ -11,16 +11,14 @@
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=10"
"node": ">=12.20"
},
"scripts": {
"test": "xo && tsd && tsc"
},
"files": [
"index.d.ts",
"base.d.ts",
"source",
"ts41"
"source"
],
"keywords": [
"typescript",
@ -35,24 +33,20 @@
],
"devDependencies": {
"@sindresorhus/tsconfig": "~0.7.0",
"expect-type": "^0.11.0",
"tsd": "^0.14.0",
"expect-type": "^0.12.0",
"tsd": "^0.17.0",
"typescript": "^4.1.3",
"xo": "^0.36.1"
"xo": "^0.43.0"
},
"types": "./index.d.ts",
"typesVersions": {
">=4.1": {
"*": [
"ts41/*"
]
}
},
"xo": {
"rules": {
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/indent": "off",
"node/no-unsupported-features/es-builtins": "off"
"node/no-unsupported-features/es-builtins": "off",
"import/extensions": "off",
"@typescript-eslint/no-redeclare": "off",
"@typescript-eslint/no-confusing-void-expression": "off"
}
}
}

View File

@ -60,7 +60,7 @@ PR welcome for additional commonly needed types and docs improvements. Read the
$ npm install type-fest
```
*Requires TypeScript >=3.8*
*Requires TypeScript >=4.2*
## Usage
@ -119,33 +119,31 @@ Click the type names for complete docs.
- [`Entries`](source/entries.d.ts) - Create a type that represents the type of the entries of a collection.
- [`SetReturnType`](source/set-return-type.d.ts) - Create a function type with a return type of your choice and the same parameters as the given function type.
- [`Asyncify`](source/asyncify.d.ts) - Create an async version of the given function type.
- [`Includes`](ts41/includes.ts) - Returns a boolean for whether the given array includes the given item.
- [`Includes`](source/includes.ts) - Returns a boolean for whether the given array includes the given item.
- [`Simplify`](source/simplify.d.ts) - Flatten the type output to improve type hints shown in editors.
### Template literal types
*Note:* These require [TypeScript 4.1 or newer](https://devblogs.microsoft.com/typescript/announcing-typescript-4-1/#template-literal-types).
- [`CamelCase`](ts41/camel-case.d.ts) Convert a string literal to camel-case (`fooBar`).
- [`CamelCasedProperties`](ts41/camel-cased-properties.d.ts) Convert object properties to camel-case (`fooBar`).
- [`CamelCasedPropertiesDeep`](ts41/camel-cased-properties-deep.d.ts) Convert object properties to camel-case recursively (`fooBar`).
- [`KebabCase`](ts41/kebab-case.d.ts) Convert a string literal to kebab-case (`foo-bar`).
- [`KebabCasedProperties`](ts41/kebab-cased-properties.d.ts) Convert a object properties to kebab-case recursively (`foo-bar`).
- [`KebabCasedPropertiesDeep`](ts41/kebab-cased-properties-deep.d.ts) Convert object properties to kebab-case (`foo-bar`).
- [`PascalCase`](ts41/pascal-case.d.ts) Converts a string literal to pascal-case (`FooBar`)
- [`PascalCasedProperties`](ts41/pascal-cased-properties.d.ts) Converts object properties to pascal-case (`FooBar`)
- [`PascalCasedPropertiesDeep`](ts41/pascal-cased-properties-deep.d.ts) Converts object properties to pascal-case (`FooBar`)
- [`SnakeCase`](ts41/snake-case.d.ts) Convert a string literal to snake-case (`foo_bar`).
- [`SnakeCasedProperties`](ts41/snake-cased-properties-deep.d.ts) Convert object properties to snake-case (`foo_bar`).
- [`SnakeCasedPropertiesDeep`](ts41/snake-cased-properties-deep.d.ts) Convert object properties to snake-case recursively (`foo_bar`).
- [`ScreamingSnakeCase`](ts41/screaming-snake-case.d.ts) - Convert a string literal to screaming-snake-case (`FOO_BAR`).
- [`DelimiterCase`](ts41/delimiter-case.d.ts) Convert a string literal to a custom string delimiter casing.
- [`DelimiterCasedProperties`](ts41/delimiter-cased-properties.d.ts) Convert object properties to a custom string delimiter casing.
- [`DelimiterCasedPropertiesDeep`](ts41/delimiter-cased-properties-deep.d.ts) Convert object properties to a custom string delimiter casing recursively.
- [`Split`](ts41/split.d.ts) - Represents an array of strings split using a given character or character set.
- [`Trim`](ts41/trim.d.ts) - Remove leading and trailing spaces from a string.
- [`Get`](ts41/get.d.ts) - Get a deeply-nested property from an object using a key path, like [Lodash's `.get()`](https://lodash.com/docs/latest#get) function.
- [`LastArrayElement`](ts41/last-array-element.d.ts) - Extracts the type of the last element of an array.
- [`CamelCase`](source/camel-case.d.ts) Convert a string literal to camel-case (`fooBar`).
- [`CamelCasedProperties`](source/camel-cased-properties.d.ts) Convert object properties to camel-case (`fooBar`).
- [`CamelCasedPropertiesDeep`](source/camel-cased-properties-deep.d.ts) Convert object properties to camel-case recursively (`fooBar`).
- [`KebabCase`](source/kebab-case.d.ts) Convert a string literal to kebab-case (`foo-bar`).
- [`KebabCasedProperties`](source/kebab-cased-properties.d.ts) Convert a object properties to kebab-case recursively (`foo-bar`).
- [`KebabCasedPropertiesDeep`](source/kebab-cased-properties-deep.d.ts) Convert object properties to kebab-case (`foo-bar`).
- [`PascalCase`](source/pascal-case.d.ts) Converts a string literal to pascal-case (`FooBar`)
- [`PascalCasedProperties`](source/pascal-cased-properties.d.ts) Converts object properties to pascal-case (`FooBar`)
- [`PascalCasedPropertiesDeep`](source/pascal-cased-properties-deep.d.ts) Converts object properties to pascal-case (`FooBar`)
- [`SnakeCase`](source/snake-case.d.ts) Convert a string literal to snake-case (`foo_bar`).
- [`SnakeCasedProperties`](source/snake-cased-properties-deep.d.ts) Convert object properties to snake-case (`foo_bar`).
- [`SnakeCasedPropertiesDeep`](source/snake-cased-properties-deep.d.ts) Convert object properties to snake-case recursively (`foo_bar`).
- [`ScreamingSnakeCase`](source/screaming-snake-case.d.ts) - Convert a string literal to screaming-snake-case (`FOO_BAR`).
- [`DelimiterCase`](source/delimiter-case.d.ts) Convert a string literal to a custom string delimiter casing.
- [`DelimiterCasedProperties`](source/delimiter-cased-properties.d.ts) Convert object properties to a custom string delimiter casing.
- [`DelimiterCasedPropertiesDeep`](source/delimiter-cased-properties-deep.d.ts) Convert object properties to a custom string delimiter casing recursively.
- [`Split`](source/split.d.ts) - Represents an array of strings split using a given character or character set.
- [`Trim`](source/trim.d.ts) - Remove leading and trailing spaces from a string.
- [`Get`](source/get.d.ts) - Get a deeply-nested property from an object using a key path, like [Lodash's `.get()`](https://lodash.com/docs/latest#get) function.
- [`LastArrayElement`](source/last-array-element.d.ts) - Extracts the type of the last element of an array.
### Miscellaneous

7
source/basic.d.ts vendored
View File

@ -1,10 +1,9 @@
// TODO: Remove the `= unknown` sometime in the future when most users are on TS 3.5 as it's now the default
/**
Matches a [`class` constructor](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes).
@category Basic
*/
export type Class<T = unknown, Arguments extends any[] = any[]> = new(...arguments_: Arguments) => T;
export type Class<T, Arguments extends any[] = any[]> = new(...arguments_: Arguments) => T;
/**
Matches a JSON object.
@ -20,9 +19,7 @@ Matches a JSON array.
@category Basic
*/
export interface JsonArray extends Array<JsonValue> {}
// TODO: Make it this when targeting TypeScript 4.1:
// export type JsonArray = JsonValue[];
export type JsonArray = JsonValue[];
/**
Matches any valid JSON value.

View File

@ -1,5 +1,5 @@
import {WordSeparators} from '../source/utilities';
import {Split} from './utilities';
import {Split} from './split';
/**
Step by step takes the first item in an array literal, formats it and adds it to a string literal, and then recursively appends the remainder.

View File

@ -42,7 +42,7 @@ const result: DelimiterCasedPropertiesDeep<UserWithFriends, '-'> = {
*/
export type DelimiterCasedPropertiesDeep<
Value,
Delimiter extends string
Delimiter extends string,
> = Value extends Function
? Value
: Value extends Array<infer U>

View File

@ -25,9 +25,9 @@ const result: DelimiterCasedProperties<User, '-'> = {
*/
export type DelimiterCasedProperties<
Value,
Delimiter extends string
Delimiter extends string,
> = Value extends Function
? Value
: Value extends Array<infer U>
? Value
: { [K in keyof Value as DelimiterCase<K, Delimiter>]: Value[K] };
: {[K in keyof Value as DelimiterCase<K, Delimiter>]: Value[K]};

View File

@ -1,5 +1,5 @@
import {Split} from './utilities';
import {StringDigit} from '../source/utilities';
import {Split} from './split';
/**
Like the `Get` type but receives an array of strings as a path parameter.

View File

@ -31,5 +31,5 @@ const pet: Pet2 = '';
*/
export type LiteralUnion<
LiteralType,
BaseType extends Primitive
BaseType extends Primitive,
> = LiteralType | (BaseType & {_?: never});

View File

@ -27,4 +27,4 @@ export type PascalCasedProperties<Value> = Value extends Function
? Value
: Value extends Array<infer U>
? Value
: { [K in keyof Value as PascalCase<K>]: Value[K] };
: {[K in keyof Value as PascalCase<K>]: Value[K]};

View File

@ -25,5 +25,5 @@ let recursiveAsyncData: PromiseValue<RecursiveAsyncData> = Promise.resolve(Promi
@category Utilities
*/
export type PromiseValue<PromiseType, Otherwise = PromiseType> = PromiseType extends Promise<infer Value>
? { 0: PromiseValue<Value>; 1: Value }[PromiseType extends Promise<unknown> ? 0 : 1]
? {0: PromiseValue<Value>; 1: Value}[PromiseType extends Promise<unknown> ? 0 : 1]
: Otherwise;

View File

@ -24,7 +24,7 @@ const responder: RequireAtLeastOne<Responder, 'text' | 'json'> = {
*/
export type RequireAtLeastOne<
ObjectType,
KeysType extends keyof ObjectType = keyof ObjectType
KeysType extends keyof ObjectType = keyof ObjectType,
> = {
// For each `Key` in `KeysType` make a mapped type:
[Key in KeysType]-?: Required<Pick<ObjectType, Key>> & // 1. Make `Key`'s type required

View File

@ -1,6 +1,3 @@
// TODO: Remove this when we target TypeScript >=3.5.
type _Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
/**
Create a type that requires exactly one of the given keys and disallows more. The remaining keys are kept as is.
@ -34,4 +31,4 @@ export type RequireExactlyOne<ObjectType, KeysType extends keyof ObjectType = ke
{[Key in KeysType]: (
Required<Pick<ObjectType, Key>> &
Partial<Record<Exclude<KeysType, Key>, never>>
)}[KeysType] & _Omit<ObjectType, KeysType>;
)}[KeysType] & Omit<ObjectType, KeysType>;

View File

@ -20,7 +20,7 @@ array = split(items, ',');
*/
export type Split<
S extends string,
Delimiter extends string
Delimiter extends string,
> = S extends `${infer Head}${Delimiter}${infer Tail}`
? [Head, ...Split<Tail, Delimiter>]
: S extends Delimiter

View File

View File

@ -1,5 +1,3 @@
/// <reference lib="es2020.bigint"/>
/**
Matches any [typed array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray), like `Uint8Array` or `Float64Array`.

View File

@ -1,5 +1,5 @@
import {expectType, expectError} from 'tsd';
import {AsyncReturnType} from '..';
import {AsyncReturnType} from '../index';
async function asyncFunction(): Promise<number> {
return Promise.resolve(2);

View File

@ -1,5 +1,5 @@
import {expectType, expectError} from 'tsd';
import {Asyncify} from '..';
import {Asyncify} from '../index';
declare function getFooSync(name: string): RegExp;
declare function getFooWithThisArgSync(this: Date, name: string): RegExp;

View File

@ -1,6 +1,5 @@
import {CamelCase} from '../ts41/camel-case';
import {Split} from '../ts41/utilities';
import {expectType, expectAssignable} from 'tsd';
import {CamelCase, Split} from '../index';
// Split
const prefixSplit: Split<'--very-prefixed', '-'> = ['', '', 'very', 'prefixed'];
@ -69,5 +68,5 @@ expectAssignable<CamelCasedProperties<RawOptions>>({
foo: 123,
bar: 'foo',
quzQux: 6,
otherField: false
otherField: false,
});

View File

@ -1,5 +1,5 @@
import {CamelCasedPropertiesDeep} from '../ts41/camel-cased-properties-deep';
import {expectType} from 'tsd';
import {CamelCasedPropertiesDeep} from '../index';
declare const foo: CamelCasedPropertiesDeep<{A: {B: number; C: Array<{D: string}>}}>;
@ -25,17 +25,17 @@ interface UserWithFriends {
const result: CamelCasedPropertiesDeep<UserWithFriends> = {
userInfo: {
userId: 1,
userName: 'Tom'
userName: 'Tom',
},
userFriends: [
{
userId: 2,
userName: 'Jerry'
userName: 'Jerry',
},
{
userId: 3,
userName: 'Spike'
}
]
userName: 'Spike',
},
],
};
expectType<CamelCasedPropertiesDeep<UserWithFriends>>(result);

View File

@ -1,5 +1,5 @@
import {CamelCasedProperties} from '../ts41/camel-cased-properties';
import {expectType} from 'tsd';
import {CamelCasedProperties} from '../index';
declare const foo: CamelCasedProperties<{A: number; B: {C: string}}>;
@ -19,6 +19,6 @@ interface User {
const result: CamelCasedProperties<User> = {
userId: 1,
userName: 'Tom'
userName: 'Tom',
};
expectType<CamelCasedProperties<User>>(result);

View File

@ -1,5 +1,5 @@
import {expectError} from 'tsd';
import {Class} from '..';
import {Class} from '../index';
class Foo {
constructor(x: number, y: any) {

View File

@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import {ConditionalExcept, Primitive} from '..';
import {ConditionalExcept, Primitive} from '../index';
class Awesome {
name!: string;

View File

@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import {ConditionalKeys} from '..';
import {ConditionalKeys} from '../index';
interface Example {
a: string;

View File

@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import {ConditionalPick, Primitive} from '..';
import {ConditionalPick, Primitive} from '../index';
class Awesome {
name!: string;

View File

@ -1,6 +1,6 @@
import {UpperCaseCharacters, WordSeparators} from '../source/utilities';
import {SplitIncludingDelimiters, DelimiterCase} from '../ts41/delimiter-case';
import {expectType, expectAssignable} from 'tsd';
import {UpperCaseCharacters, WordSeparators} from '../source/utilities';
import {SplitIncludingDelimiters, DelimiterCase} from '../source/delimiter-case';
const splitFromCamel: SplitIncludingDelimiters<'fooBar', WordSeparators | UpperCaseCharacters> = ['foo', 'B', 'ar'];
expectType<['foo', 'B', 'ar']>(splitFromCamel);
@ -57,5 +57,5 @@ interface CliOptions {
expectAssignable<OddCasedProperties<CliOptions>>({
'dry#run': true,
'include#file': 'bar.js',
foo: 123
foo: 123,
});

View File

@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import {DelimiterCasedPropertiesDeep} from '../ts41/delimiter-cased-properties-deep';
import {DelimiterCasedPropertiesDeep} from '../index';
declare const foo: DelimiterCasedPropertiesDeep<{helloWorld: {fooBar: string}}, '/'>;
expectType<{'hello/world': {'foo/bar': string}}>(foo);
@ -24,17 +24,17 @@ interface UserWithFriends {
const result: DelimiterCasedPropertiesDeep<UserWithFriends, '-'> = {
'user-info': {
'user-id': 1,
'user-name': 'Tom'
'user-name': 'Tom',
},
'user-friends': [
{
'user-id': 2,
'user-name': 'Jerry'
'user-name': 'Jerry',
},
{
'user-id': 3,
'user-name': 'Spike'
}
]
'user-name': 'Spike',
},
],
};
expectType<DelimiterCasedPropertiesDeep<UserWithFriends, '-'>>(result);

View File

@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import {DelimiterCasedProperties} from '../ts41/delimiter-cased-properties';
import {DelimiterCasedProperties} from '../index';
declare const foo: DelimiterCasedProperties<{helloWorld: {fooBar: string}}, '/'>;
expectType<{'hello/world': {fooBar: string}}>(foo);
@ -17,6 +17,6 @@ interface User {
}
const result: DelimiterCasedProperties<User, '-'> = {
'user-id': 1,
'user-name': 'Tom'
'user-name': 'Tom',
};
expectType<DelimiterCasedProperties<User, '-'>>(result);

View File

@ -1,6 +1,6 @@
import {Entries} from '../source/entries';
import {Entry} from '../source/entry';
import {expectAssignable} from 'tsd';
import {Entries} from '../index';
import {Entry} from '../source/entry';
// Objects
const objectExample = {a: 1};
@ -31,7 +31,7 @@ expectAssignable<[number, (string | number)]>(arrayEntryNumber);
const arrayEntries: Entries<typeof arrayExample> = [
arrayEntryString,
arrayEntryNumber
arrayEntryNumber,
];
expectAssignable<Array<[number, (string | number)]>>(arrayEntries);
@ -46,6 +46,6 @@ expectAssignable<[(string | number), (string | number)]>(setEntryNumber);
const setEntries: Entries<typeof setExample> = [
setEntryString,
setEntryNumber
setEntryNumber,
];
expectAssignable<Array<[(string | number), (string | number)]>>(setEntries);

View File

@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import {Except} from '..';
import {Except} from '../index';
declare const except: Except<{a: number; b: string}, 'b'>;
expectType<{a: number}>(except);

View File

@ -1,5 +1,5 @@
import {expectAssignable, expectNotAssignable} from 'tsd';
import {FixedLengthArray} from '..';
import {FixedLengthArray} from '../index';
type FixedToThreeStrings = FixedLengthArray<string, 3>;

View File

@ -1,5 +1,5 @@
import {Get} from '../ts41/get';
import {expectTypeOf} from 'expect-type';
import {Get} from '../index';
declare const get: <ObjectType, Path extends string>(object: ObjectType, path: Path) => Get<ObjectType, Path>;
@ -36,7 +36,7 @@ interface WithTuples {
},
{
baz: boolean;
}
},
];
}

View File

@ -1,5 +1,5 @@
import {expectError, expectType} from 'tsd';
import {Includes} from '..';
import {Includes} from '../index';
const includesEmptyArray: Includes<[], 'abc'> = false;
expectType<false>(includesEmptyArray);
@ -15,7 +15,7 @@ const includesComplexMultiTypeArray: Includes<[
},
true,
null,
'abcd'
'abcd',
], 'abc'> = false;
expectType<false>(includesComplexMultiTypeArray);

View File

@ -1,10 +1,12 @@
import {expectType} from 'tsd';
import {ObservableLike} from '..';
import {expectType, expectAssignable} from 'tsd';
import {ObservableLike} from '../index';
// eslint-disable-next-line no-use-extend-native/no-use-extend-native
expectType<symbol>(Symbol.observable);
expectAssignable<symbol>(Symbol.observable);
const observable = (null as any) as ObservableLike;
observable.subscribe(() => {}); // eslint-disable-line @typescript-eslint/no-empty-function
observable.subscribe(value => expectType<unknown>(value));
observable.subscribe(value => {
expectType<unknown>(value);
});

View File

@ -1,5 +1,5 @@
import {IterableElement} from '../source/iterable-element';
import {expectType} from 'tsd';
import {IterableElement} from '../index';
declare const iterableElement: IterableElement<ReturnType<typeof secretGenerator>>;
expectType<1 | 'two'>(iterableElement);

View File

@ -1,7 +1,5 @@
import {
KebabCase
} from '../ts41/kebab-case';
import {expectType} from 'tsd';
import {KebabCase} from '../index';
const kebabFromCamel: KebabCase<'fooBar'> = 'foo-bar';
expectType<'foo-bar'>(kebabFromCamel);

View File

@ -1,5 +1,5 @@
import {KebabCasedPropertiesDeep} from '../ts41/kebab-cased-properties-deep';
import {expectType} from 'tsd';
import {KebabCasedPropertiesDeep} from '../index';
declare const foo: KebabCasedPropertiesDeep<{helloWorld: {fooBar: string}}>;
expectType<{'hello-world': {'foo-bar': string}}>(foo);
@ -21,17 +21,17 @@ interface UserWithFriends {
const result: KebabCasedPropertiesDeep<UserWithFriends> = {
'user-info': {
'user-id': 1,
'user-name': 'Tom'
'user-name': 'Tom',
},
'user-friends': [
{
'user-id': 2,
'user-name': 'Jerry'
'user-name': 'Jerry',
},
{
'user-id': 3,
'user-name': 'Spike'
}
]
'user-name': 'Spike',
},
],
};
expectType<KebabCasedPropertiesDeep<UserWithFriends>>(result);

View File

@ -1,5 +1,5 @@
import {KebabCasedProperties} from '../ts41/kebab-cased-properties';
import {expectType} from 'tsd';
import {KebabCasedProperties} from '../index';
declare const foo: KebabCasedProperties<{helloWorld: {fooBar: string}}>;
expectType<{'hello-world': {fooBar: string}}>(foo);
@ -11,6 +11,6 @@ interface User {
}
const result: KebabCasedProperties<User> = {
'user-id': 1,
'user-name': 'Tom'
'user-name': 'Tom',
};
expectType<KebabCasedProperties<User>>(result);

View File

@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import {LastArrayElement} from '../ts41';
import {LastArrayElement} from '../index';
declare function lastOf<V extends [any, ...any]>(array: V): LastArrayElement<V>;
const array: ['foo', 2, 'bar'] = ['foo', 2, 'bar'];

View File

@ -1,5 +1,5 @@
import {expectError, expectAssignable} from 'tsd';
import {MergeExclusive} from '..';
import {MergeExclusive} from '../index';
interface BaseOptions {
option?: string;
@ -19,10 +19,10 @@ const exclusiveVariation1: Options = {exclusive1: true};
const exclusiveVariation2: Options = {exclusive2: 1};
expectAssignable<{option?: string; exclusive1: boolean; exclusive2?: string}>(
exclusiveVariation1
exclusiveVariation1,
);
expectAssignable<{option?: string; exclusive1?: string; exclusive2: number}>(
exclusiveVariation2
exclusiveVariation2,
);
expectError<Options>({exclusive1: true, exclusive2: 1});

View File

@ -1,5 +1,5 @@
import {expectAssignable} from 'tsd';
import {Merge} from '..';
import {Merge} from '../index';
type Foo = {
a: number;

View File

@ -1,5 +1,5 @@
import {expectType, expectError} from 'tsd';
import {Mutable} from '..';
import {Mutable} from '../index';
type Foo = {
readonly a: number;

View File

@ -1,5 +1,5 @@
import {expectAssignable, expectError} from 'tsd';
import {Opaque} from '..';
import {Opaque} from '../index';
type Value = Opaque<number, 'Value'>;

View File

@ -1,5 +1,5 @@
import {expectType, expectAssignable, expectNotAssignable} from 'tsd';
import {PackageJson, LiteralUnion} from '..';
import {PackageJson, LiteralUnion} from '../index';
const packageJson: PackageJson = {};
@ -22,14 +22,14 @@ expectType<string | undefined>(packageJson.typings);
expectType<string | string[] | undefined>(packageJson.man);
expectType<PackageJson.DirectoryLocations | undefined>(packageJson.directories);
expectType<{type: string; url: string; directory?: string} | string | undefined>(
packageJson.repository
packageJson.repository,
);
expectType<PackageJson.Scripts | undefined>(packageJson.scripts);
expectType<Record<string, unknown> | undefined>(packageJson.config);
expectType<PackageJson.Dependency | undefined>(packageJson.dependencies);
expectType<PackageJson.Dependency | undefined>(packageJson.devDependencies);
expectType<PackageJson.Dependency | undefined>(
packageJson.optionalDependencies
packageJson.optionalDependencies,
);
expectType<PackageJson.Dependency | undefined>(packageJson.peerDependencies);
expectType<string[] | undefined>(packageJson.bundleDependencies);

View File

@ -1,5 +1,5 @@
import {expectType, expectError, expectAssignable} from 'tsd';
import {PartialDeep} from '..';
import {PartialDeep} from '../index';
const foo = {
baz: 'fred',
@ -19,8 +19,8 @@ const foo = {
readonlyMap: new Map<string, string>() as ReadonlyMap<string, string>,
readonlySet: new Set<string>() as ReadonlySet<string>,
readonlyArray: ['foo'] as readonly string[],
readonlyTuple: ['foo'] as const
}
readonlyTuple: ['foo'] as const,
},
};
let partialDeepFoo: PartialDeep<typeof foo> = foo;

View File

@ -1,5 +1,5 @@
import {PascalCase} from '../ts41/pascal-case';
import {expectType} from 'tsd';
import {PascalCase} from '../index';
const pascalFromCamel: PascalCase<'fooBar'> = 'FooBar';
expectType<'FooBar'>(pascalFromCamel);

View File

@ -1,5 +1,5 @@
import {PascalCasedPropertiesDeep} from '../ts41/pascal-cased-properties-deep';
import {expectType} from 'tsd';
import {PascalCasedPropertiesDeep} from '../index';
declare const foo: PascalCasedPropertiesDeep<{helloWorld: {fooBar: string}}>;
expectType<{HelloWorld: {FooBar: string}}>(foo);
@ -24,17 +24,17 @@ interface UserWithFriends {
const result: PascalCasedPropertiesDeep<UserWithFriends> = {
UserInfo: {
UserId: 1,
UserName: 'Tom'
UserName: 'Tom',
},
UserFriends: [
{
UserId: 2,
UserName: 'Jerry'
UserName: 'Jerry',
},
{
UserId: 3,
UserName: 'Spike'
}
]
UserName: 'Spike',
},
],
};
expectType<PascalCasedPropertiesDeep<UserWithFriends>>(result);

View File

@ -1,5 +1,5 @@
import {PascalCasedProperties} from '../ts41/pascal-cased-properties';
import {expectType} from 'tsd';
import {PascalCasedProperties} from '../index';
declare const foo: PascalCasedProperties<{helloWorld: {fooBar: string}}>;
expectType<{HelloWorld: {fooBar: string}}>(foo);
@ -17,6 +17,6 @@ interface User {
}
const result: PascalCasedProperties<User> = {
UserId: 1,
UserName: 'Tom'
UserName: 'Tom',
};
expectType<PascalCasedProperties<User>>(result);

View File

@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import {Promisable} from '..';
import {Promisable} from '../index';
declare const promisable: Promisable<string>;
expectType<PromiseLike<string> | string>(promisable);

View File

@ -1,5 +1,5 @@
import {expectAssignable} from 'tsd';
import {PromiseValue} from '..';
import {PromiseValue} from '../index';
type NumberPromise = Promise<number>;
type NestedPromise = Promise<NumberPromise>;

View File

@ -1,9 +1,9 @@
import {expectType, expectError} from 'tsd';
import {ReadonlyDeep} from '../source/readonly-deep';
import {ReadonlyDeep} from '../index';
const data = {
object: {
foo: 'bar'
foo: 'bar',
},
fn: (_: string) => true,
string: 'foo',
@ -19,7 +19,7 @@ const data = {
readonlyMap: new Map<string, string>() as ReadonlyMap<string, string>,
readonlySet: new Set<string>() as ReadonlySet<string>,
readonlyArray: ['foo'] as readonly string[],
readonlyTuple: ['foo'] as const
readonlyTuple: ['foo'] as const,
};
const readonlyData: ReadonlyDeep<typeof data> = data;

View File

@ -1,5 +1,5 @@
import {expectError, expectAssignable} from 'tsd';
import {RequireAtLeastOne} from '..';
import {RequireAtLeastOne} from '../index';
type SystemMessages = {
default: string;
@ -32,10 +32,10 @@ declare const atLeastOneWithoutKeys: RequireAtLeastOne<{
b: number;
}>;
expectAssignable<{a: number; b?: number} | {a?: number; b: number}>(
atLeastOneWithoutKeys
atLeastOneWithoutKeys,
);
expectAssignable<MessageBoard<ValidMessages>>(
({macos = '', linux = '🐧', windows = '⊞'}) =>
`${linux} + ${windows} = ${macos}`
`${linux} + ${windows} = ${macos}`,
);

View File

@ -1,5 +1,5 @@
import {expectError, expectAssignable} from 'tsd';
import {RequireExactlyOne} from '..';
import {RequireExactlyOne} from '../index';
type SystemMessages = {
default: string;

View File

@ -1,5 +1,5 @@
import {ScreamingSnakeCase} from '../ts41/screaming-snake-case';
import {expectType} from 'tsd';
import {ScreamingSnakeCase} from '../index';
const screamingSnakeFromCamel: ScreamingSnakeCase<'fooBar'> = 'FOO_BAR';
expectType<'FOO_BAR'>(screamingSnakeFromCamel);

View File

@ -1,5 +1,5 @@
import {expectType, expectError} from 'tsd';
import {SetOptional} from '..';
import {SetOptional} from '../index';
// Update one required and one optional to optional.
declare const variation1: SetOptional<{a: number; b?: string; c: boolean}, 'b' | 'c'>;

View File

@ -1,5 +1,5 @@
import {expectType, expectError} from 'tsd';
import {SetRequired} from '..';
import {SetRequired} from '../index';
// Update one required and one optional to required.
declare const variation1: SetRequired<{a?: number; b: string; c?: boolean}, 'b' | 'c'>;

View File

@ -1,5 +1,5 @@
import {expectType, expectError} from 'tsd';
import {SetReturnType} from '..';
import {SetReturnType} from '../index';
declare const anything: unknown;

View File

@ -1,7 +1,5 @@
import {
SnakeCase
} from '../ts41/snake-case';
import {expectType} from 'tsd';
import {SnakeCase} from '../index';
const snakeFromCamel: SnakeCase<'fooBar'> = 'foo_bar';
expectType<'foo_bar'>(snakeFromCamel);

View File

@ -1,5 +1,5 @@
import {SnakeCasedPropertiesDeep} from '../ts41/snake-cased-properties-deep';
import {expectType} from 'tsd';
import {SnakeCasedPropertiesDeep} from '../index';
declare const foo: SnakeCasedPropertiesDeep<{helloWorld: {fooBar: string}}>;
expectType<{hello_world: {foo_bar: string}}>(foo);
@ -21,17 +21,17 @@ interface UserWithFriends {
const result: SnakeCasedPropertiesDeep<UserWithFriends> = {
user_info: {
user_id: 1,
user_name: 'Tom'
user_name: 'Tom',
},
user_friends: [
{
user_id: 2,
user_name: 'Jerry'
user_name: 'Jerry',
},
{
user_id: 3,
user_name: 'Spike'
}
]
user_name: 'Spike',
},
],
};
expectType<SnakeCasedPropertiesDeep<UserWithFriends>>(result);

View File

@ -1,5 +1,5 @@
import {SnakeCasedProperties} from '../ts41/snake-cased-properties';
import {expectType} from 'tsd';
import {SnakeCasedProperties} from '../index';
declare const foo: SnakeCasedProperties<{helloWorld: {fooBar: string}}>;
expectType<{hello_world: {fooBar: string}}>(foo);
@ -11,6 +11,6 @@ interface User {
}
const result: SnakeCasedProperties<User> = {
user_id: 1,
user_name: 'Tom'
user_name: 'Tom',
};
expectType<SnakeCasedProperties<User>>(result);

View File

@ -1,9 +1,9 @@
import {expectType} from 'tsd';
import {Split} from '../ts41';
import {Split} from '../index';
declare function split<
S extends string,
Delimiter extends string
Delimiter extends string,
>(string: S, separator: Delimiter): Split<S, Delimiter>;
const items = 'foo,bar,baz,waldo';
@ -17,7 +17,7 @@ expectType<['foo,bar,baz,waldo']>(split(items, ' '));
// Empty string split (every character).
expectType<[
'f', 'o', 'o', ',', 'b', 'a', 'r', ',',
'b', 'a', 'z', ',', 'w', 'a', 'l', 'd', 'o'
'b', 'a', 'z', ',', 'w', 'a', 'l', 'd', 'o',
]>(split(items, ''));
// Split single same character.

View File

@ -1,5 +1,5 @@
import {expectType, expectError} from 'tsd';
import {Stringified} from '..';
import {Stringified} from '../index';
declare const stringified: Stringified<{a: number; b: string}>;
expectType<{a: string; b: string}>(stringified);

View File

@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import {Trim} from '../ts41';
import {Trim} from '../index';
declare function trim<S extends string>(value: S): Trim<S>;

View File

@ -1,6 +1,6 @@
// Ensure that TypeScript 4.1 types are available.
import {CamelCase} from '..';
import {expectType} from 'tsd';
import {CamelCase} from '../index';
const camelFromPascal: CamelCase<'FooBar'> = 'fooBar';
expectType<CamelCase<'FooBar'>>(camelFromPascal);

View File

@ -1,5 +1,5 @@
import {expectType} from 'tsd';
import {TsConfigJson} from '..';
import {TsConfigJson} from '../index';
const tsConfig: TsConfigJson = {};

View File

@ -1,5 +1,5 @@
import {expectAssignable} from 'tsd';
import {UnionToIntersection} from '..';
import {UnionToIntersection} from '../index';
declare const intersection1: UnionToIntersection<{a: string} | {b: number}>;
expectAssignable<{a: string; b: number}>(intersection1);

View File

@ -1,5 +1,5 @@
import {expectType, expectError, expectAssignable} from 'tsd';
import {ValueOf} from '..';
import {ValueOf} from '../index';
const value: ValueOf<{a: 1; b: 2; c: 3}> = 3;
const valueRestricted: ValueOf<{a: 1; b: 2; c: 3}, 'a'> = 1;

25
ts41/index.d.ts vendored
View File

@ -1,25 +0,0 @@
// These are all the basic types that's compatible with all supported TypeScript versions.
export * from '../base';
// These are special types that require at least TypeScript 4.1.
export {CamelCase} from './camel-case';
export {CamelCasedProperties} from './camel-cased-properties';
export {CamelCasedPropertiesDeep} from './camel-cased-properties-deep';
export {KebabCase} from './kebab-case';
export {KebabCasedProperties} from './kebab-cased-properties';
export {KebabCasedPropertiesDeep} from './kebab-cased-properties-deep';
export {PascalCase} from './pascal-case';
export {PascalCasedProperties} from './pascal-cased-properties';
export {PascalCasedPropertiesDeep} from './pascal-cased-properties-deep';
export {SnakeCase} from './snake-case';
export {SnakeCasedProperties} from './snake-cased-properties';
export {SnakeCasedPropertiesDeep} from './snake-cased-properties-deep';
export {ScreamingSnakeCase} from './screaming-snake-case';
export {DelimiterCase} from './delimiter-case';
export {DelimiterCasedProperties} from './delimiter-cased-properties';
export {DelimiterCasedPropertiesDeep} from './delimiter-cased-properties-deep';
export {Split} from './split';
export {Trim} from './trim';
export {Includes} from './includes';
export {Get} from './get';
export {LastArrayElement} from './last-array-element';

8
ts41/utilities.d.ts vendored
View File

@ -1,8 +0,0 @@
/**
Recursively split a string literal into two parts on the first occurence of the given string, returning an array literal of all the separate parts.
*/
export type Split<S extends string, D extends string> =
string extends S ? string[] :
S extends '' ? [] :
S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] :
[S];

View File

@ -4,7 +4,6 @@
"noEmit": true
},
"exclude": [
"test-d/**/*",
"ts41/**/*"
"test-d/**/*"
]
}