diff --git a/.eslintrc.base.cjs b/.eslintrc.base.cjs index b897f3a1..c5e3aed0 100644 --- a/.eslintrc.base.cjs +++ b/.eslintrc.base.cjs @@ -303,7 +303,26 @@ const config = { allowTemplateLiterals: true } ], - '@typescript-eslint/sort-type-union-intersection-members': 2, + '@typescript-eslint/sort-type-constituents': [ + 2, + { + checkIntersections: true, + checkUnions: true, + groupOrder: [ + 'named', + 'keyword', + 'operator', + 'literal', + 'function', + 'import', + 'conditional', + 'object', + 'tuple', + 'intersection', + 'union' + ] + } + ], '@typescript-eslint/triple-slash-reference': [ 2, { @@ -1015,6 +1034,8 @@ const config = { }, plugins: ['chai-expect', 'jest-formatting'], rules: { + '@typescript-eslint/ban-types': 0, + '@typescript-eslint/consistent-indexed-object-style': 0, '@typescript-eslint/no-base-to-string': 0, '@typescript-eslint/no-empty-function': 0, '@typescript-eslint/no-unused-expressions': 0, diff --git a/__fixtures__/ordered-pair.ts b/__fixtures__/ordered-pair.ts new file mode 100644 index 00000000..faaab457 --- /dev/null +++ b/__fixtures__/ordered-pair.ts @@ -0,0 +1,26 @@ +/** + * @file Fixtures - OrderedPair + * @module fixtures/OrderedPair + */ + +/** + * Pair of numbers representing a single point on a two-dimensional grid. + * + * @see https://splashlearn.com/math-vocabulary/geometry/ordered-pair + */ +interface IOrderedPair { + x: number + y: number +} + +/** + * Pair of numbers representing a single point on a two-dimensional grid. + * + * @see https://splashlearn.com/math-vocabulary/geometry/ordered-pair + */ +type TOrderedPair = { + x: number + y: number +} + +export type { IOrderedPair, TOrderedPair } diff --git a/__fixtures__/person.ts b/__fixtures__/person.ts new file mode 100644 index 00000000..023c9e7c --- /dev/null +++ b/__fixtures__/person.ts @@ -0,0 +1,38 @@ +/** + * @file Fixtures - Person + * @module fixtures/Person + */ + +/** + * Data model representing a person. + * + * @class + */ +class Person { + /** + * @public + * @instance + * @member {string} first_name - First name + */ + public first_name: string + + /** + * @public + * @instance + * @member {string} last_name - Last name + */ + public last_name: string + + /** + * Creates a new person. + * + * @param {string} first_name - First name + * @param {string} last_name - Last name + */ + constructor(first_name: string, last_name: string) { + this.first_name = first_name + this.last_name = last_name + } +} + +export default Person diff --git a/src/enums/__tests__/app-env.spec-d.ts b/src/enums/__tests__/app-env.spec-d.ts new file mode 100644 index 00000000..55b9b978 --- /dev/null +++ b/src/enums/__tests__/app-env.spec-d.ts @@ -0,0 +1,38 @@ +/** + * @file Type Tests - AppEnv + * @module tutils/enums/tests/unit-d/AppEnv + */ + +import type TestSubject from '../app-env' + +describe('unit-d:enums/AppEnv', () => { + it('should match [CI = "ci"]', () => { + expectTypeOf() + .toHaveProperty('CI') + .toMatchTypeOf<'ci'>() + }) + + it('should match [DEV = "development"]', () => { + expectTypeOf() + .toHaveProperty('DEV') + .toMatchTypeOf<'development'>() + }) + + it('should match [PROD = "production"]', () => { + expectTypeOf() + .toHaveProperty('PROD') + .toMatchTypeOf<'production'>() + }) + + it('should match [STG = "staging"]', () => { + expectTypeOf() + .toHaveProperty('STG') + .toMatchTypeOf<'staging'>() + }) + + it('should match [TEST = "test"]', () => { + expectTypeOf() + .toHaveProperty('TEST') + .toMatchTypeOf<'test'>() + }) +}) diff --git a/src/enums/__tests__/bson-type-alias.spec-d.ts b/src/enums/__tests__/bson-type-alias.spec-d.ts new file mode 100644 index 00000000..ba2421a7 --- /dev/null +++ b/src/enums/__tests__/bson-type-alias.spec-d.ts @@ -0,0 +1,44 @@ +/** + * @file Type Tests - BsonTypeAlias + * @module tutils/enums/tests/unit-d/BsonTypeAlias + */ + +import type TestSubject from '../bson-type-alias' + +describe('unit-d:enums/BsonTypeAlias', () => { + it('should match [BOOL = "bool"]', () => { + expectTypeOf() + .toHaveProperty('BOOL') + .toMatchTypeOf<'bool'>() + }) + + it('should match [DECIMAL = "decimal"]', () => { + expectTypeOf() + .toHaveProperty('DECIMAL') + .toMatchTypeOf<'decimal'>() + }) + + it('should match [DOUBLE = "double"]', () => { + expectTypeOf() + .toHaveProperty('DOUBLE') + .toMatchTypeOf<'double'>() + }) + + it('should match [INT = "int"]', () => { + expectTypeOf() + .toHaveProperty('INT') + .toMatchTypeOf<'int'>() + }) + + it('should match [LONG = "long"]', () => { + expectTypeOf() + .toHaveProperty('LONG') + .toMatchTypeOf<'long'>() + }) + + it('should match [REGEX = "regex"]', () => { + expectTypeOf() + .toHaveProperty('REGEX') + .toMatchTypeOf<'regex'>() + }) +}) diff --git a/src/enums/__tests__/bson-type-code.spec-d.ts b/src/enums/__tests__/bson-type-code.spec-d.ts new file mode 100644 index 00000000..92da1b39 --- /dev/null +++ b/src/enums/__tests__/bson-type-code.spec-d.ts @@ -0,0 +1,40 @@ +/** + * @file Type Tests - BsonTypeCode + * @module tutils/enums/tests/unit-d/BsonTypeCode + */ + +import type TestSubject from '../bson-type-code' + +describe('unit-d:enums/BsonTypeCode', () => { + it('should match [BOOL = 8]', () => { + expectTypeOf().toHaveProperty('BOOL').toEqualTypeOf<8>() + }) + + it('should match [DECIMAL = 19]', () => { + expectTypeOf() + .toHaveProperty('DECIMAL') + .toEqualTypeOf<19>() + }) + + it('should match [DOUBLE = 1]', () => { + expectTypeOf() + .toHaveProperty('DOUBLE') + .toEqualTypeOf<1>() + }) + + it('should match [INT = 16]', () => { + expectTypeOf().toHaveProperty('INT').toEqualTypeOf<16>() + }) + + it('should match [LONG = 18]', () => { + expectTypeOf() + .toHaveProperty('LONG') + .toEqualTypeOf<18>() + }) + + it('should match [REGEX = 11]', () => { + expectTypeOf() + .toHaveProperty('REGEX') + .toEqualTypeOf<11>() + }) +}) diff --git a/src/enums/__tests__/compare-result.spec-d.ts b/src/enums/__tests__/compare-result.spec-d.ts new file mode 100644 index 00000000..1f8c881d --- /dev/null +++ b/src/enums/__tests__/compare-result.spec-d.ts @@ -0,0 +1,26 @@ +/** + * @file Type Tests - CompareResult + * @module tutils/enums/tests/unit-d/CompareResult + */ + +import type TestSubject from '../compare-result' + +describe('unit-d:enums/CompareResult', () => { + it('should match [EQUAL = 8]', () => { + expectTypeOf() + .toHaveProperty('EQUAL') + .toEqualTypeOf<0>() + }) + + it('should match [GREATER_THAN = 1]', () => { + expectTypeOf() + .toHaveProperty('GREATER_THAN') + .toEqualTypeOf<1>() + }) + + it('should match [LESS_THAN = -1]', () => { + expectTypeOf() + .toHaveProperty('LESS_THAN') + .toEqualTypeOf<-1>() + }) +}) diff --git a/src/enums/__tests__/http-status.spec-d.ts b/src/enums/__tests__/http-status.spec-d.ts new file mode 100644 index 00000000..a004c4dc --- /dev/null +++ b/src/enums/__tests__/http-status.spec-d.ts @@ -0,0 +1,372 @@ +/** + * @file Type Tests - HttpStatus + * @module tutils/enums/tests/unit-d/HttpStatus + */ + +import type TestSubject from '../http-status' + +describe('unit-d:enums/HttpStatus', () => { + it('should match [CONTINUE = 100]', () => { + expectTypeOf() + .toHaveProperty('CONTINUE') + .toEqualTypeOf<100>() + }) + + it('should match [SWITCHING_PROTOCOLS = 101]', () => { + expectTypeOf() + .toHaveProperty('SWITCHING_PROTOCOLS') + .toEqualTypeOf<101>() + }) + + it('should match [PROCESSING = 102]', () => { + expectTypeOf() + .toHaveProperty('PROCESSING') + .toEqualTypeOf<102>() + }) + + it('should match [EARLYHINTS = 103]', () => { + expectTypeOf() + .toHaveProperty('EARLYHINTS') + .toEqualTypeOf<103>() + }) + + it('should match [OK = 200]', () => { + expectTypeOf().toHaveProperty('OK').toEqualTypeOf<200>() + }) + + it('should match [CREATED = 201]', () => { + expectTypeOf() + .toHaveProperty('CREATED') + .toEqualTypeOf<201>() + }) + + it('should match [ACCEPTED = 202]', () => { + expectTypeOf() + .toHaveProperty('ACCEPTED') + .toEqualTypeOf<202>() + }) + + it('should match [NON_AUTHORITATIVE_INFORMATION = 203]', () => { + expectTypeOf() + .toHaveProperty('NON_AUTHORITATIVE_INFORMATION') + .toEqualTypeOf<203>() + }) + + it('should match [NO_CONTENT = 204]', () => { + expectTypeOf() + .toHaveProperty('NO_CONTENT') + .toEqualTypeOf<204>() + }) + + it('should match [RESET_CONTENT = 205]', () => { + expectTypeOf() + .toHaveProperty('RESET_CONTENT') + .toEqualTypeOf<205>() + }) + + it('should match [PARTIAL_CONTENT = 206]', () => { + expectTypeOf() + .toHaveProperty('PARTIAL_CONTENT') + .toEqualTypeOf<206>() + }) + + it('should match [MULTI_STATUS = 207]', () => { + expectTypeOf() + .toHaveProperty('MULTI_STATUS') + .toEqualTypeOf<207>() + }) + + it('should match [ALREADY_REPORTED = 208]', () => { + expectTypeOf() + .toHaveProperty('ALREADY_REPORTED') + .toEqualTypeOf<208>() + }) + + it('should match [IM_USED = 226]', () => { + expectTypeOf() + .toHaveProperty('IM_USED') + .toEqualTypeOf<226>() + }) + + it('should match [AMBIGUOUS = 300]', () => { + expectTypeOf() + .toHaveProperty('AMBIGUOUS') + .toEqualTypeOf<300>() + }) + + it('should match [MOVED_PERMANENTLY = 301]', () => { + expectTypeOf() + .toHaveProperty('MOVED_PERMANENTLY') + .toEqualTypeOf<301>() + }) + + it('should match [FOUND = 302]', () => { + expectTypeOf() + .toHaveProperty('FOUND') + .toEqualTypeOf<302>() + }) + + it('should match [SEE_OTHER = 303]', () => { + expectTypeOf() + .toHaveProperty('SEE_OTHER') + .toEqualTypeOf<303>() + }) + + it('should match [NOT_MODIFIED = 304]', () => { + expectTypeOf() + .toHaveProperty('NOT_MODIFIED') + .toEqualTypeOf<304>() + }) + + it('should match [TEMPORARY_REDIRECT = 307]', () => { + expectTypeOf() + .toHaveProperty('TEMPORARY_REDIRECT') + .toEqualTypeOf<307>() + }) + + it('should match [PERMANENT_REDIRECT = 308]', () => { + expectTypeOf() + .toHaveProperty('PERMANENT_REDIRECT') + .toEqualTypeOf<308>() + }) + + it('should match [BAD_REQUEST = 400]', () => { + expectTypeOf() + .toHaveProperty('BAD_REQUEST') + .toEqualTypeOf<400>() + }) + + it('should match [UNAUTHORIZED = 401]', () => { + expectTypeOf() + .toHaveProperty('UNAUTHORIZED') + .toEqualTypeOf<401>() + }) + + it('should match [PAYMENT_REQUIRED = 402]', () => { + expectTypeOf() + .toHaveProperty('PAYMENT_REQUIRED') + .toEqualTypeOf<402>() + }) + + it('should match [FORBIDDEN = 403]', () => { + expectTypeOf() + .toHaveProperty('FORBIDDEN') + .toEqualTypeOf<403>() + }) + + it('should match [NOT_FOUND = 404]', () => { + expectTypeOf() + .toHaveProperty('NOT_FOUND') + .toEqualTypeOf<404>() + }) + + it('should match [METHOD_NOT_ALLOWED = 405]', () => { + expectTypeOf() + .toHaveProperty('METHOD_NOT_ALLOWED') + .toEqualTypeOf<405>() + }) + + it('should match [NOT_ACCEPTABLE = 406]', () => { + expectTypeOf() + .toHaveProperty('NOT_ACCEPTABLE') + .toEqualTypeOf<406>() + }) + + it('should match [PROXY_AUTHENTICATION_REQUIRED = 407]', () => { + expectTypeOf() + .toHaveProperty('PROXY_AUTHENTICATION_REQUIRED') + .toEqualTypeOf<407>() + }) + + it('should match [REQUEST_TIMEOUT = 408]', () => { + expectTypeOf() + .toHaveProperty('REQUEST_TIMEOUT') + .toEqualTypeOf<408>() + }) + + it('should match [CONFLICT = 409]', () => { + expectTypeOf() + .toHaveProperty('CONFLICT') + .toEqualTypeOf<409>() + }) + + it('should match [GONE = 410]', () => { + expectTypeOf() + .toHaveProperty('GONE') + .toEqualTypeOf<410>() + }) + + it('should match [LENGTH_REQUIRED = 411]', () => { + expectTypeOf() + .toHaveProperty('LENGTH_REQUIRED') + .toEqualTypeOf<411>() + }) + + it('should match [PRECONDITION_FAILED = 412]', () => { + expectTypeOf() + .toHaveProperty('PRECONDITION_FAILED') + .toEqualTypeOf<412>() + }) + + it('should match [PAYLOAD_TOO_LARGE = 413]', () => { + expectTypeOf() + .toHaveProperty('PAYLOAD_TOO_LARGE') + .toEqualTypeOf<413>() + }) + + it('should match [URI_TOO_LONG = 414]', () => { + expectTypeOf() + .toHaveProperty('URI_TOO_LONG') + .toEqualTypeOf<414>() + }) + + it('should match [UNSUPPORTED_MEDIA_TYPE = 415]', () => { + expectTypeOf() + .toHaveProperty('UNSUPPORTED_MEDIA_TYPE') + .toEqualTypeOf<415>() + }) + + it('should match [RANGE_NOT_SATISFIABLE = 416]', () => { + expectTypeOf() + .toHaveProperty('RANGE_NOT_SATISFIABLE') + .toEqualTypeOf<416>() + }) + + it('should match [EXPECTATION_FAILED = 417]', () => { + expectTypeOf() + .toHaveProperty('EXPECTATION_FAILED') + .toEqualTypeOf<417>() + }) + + it('should match [IM_A_TEAPOT = 418]', () => { + expectTypeOf() + .toHaveProperty('IM_A_TEAPOT') + .toEqualTypeOf<418>() + }) + + it('should match [MISDIRECTED = 421]', () => { + expectTypeOf() + .toHaveProperty('MISDIRECTED') + .toEqualTypeOf<421>() + }) + + it('should match [UNPROCESSABLE_ENTITY = 422]', () => { + expectTypeOf() + .toHaveProperty('UNPROCESSABLE_ENTITY') + .toEqualTypeOf<422>() + }) + + it('should match [LOCKED = 423]', () => { + expectTypeOf() + .toHaveProperty('LOCKED') + .toEqualTypeOf<423>() + }) + + it('should match [FAILED_DEPENDENCY = 424]', () => { + expectTypeOf() + .toHaveProperty('FAILED_DEPENDENCY') + .toEqualTypeOf<424>() + }) + + it('should match [TOO_EARLY = 425]', () => { + expectTypeOf() + .toHaveProperty('TOO_EARLY') + .toEqualTypeOf<425>() + }) + + it('should match [UPGRADE_REQUIRED = 426]', () => { + expectTypeOf() + .toHaveProperty('UPGRADE_REQUIRED') + .toEqualTypeOf<426>() + }) + + it('should match [PRECONDITION_REQUIRED = 428]', () => { + expectTypeOf() + .toHaveProperty('PRECONDITION_REQUIRED') + .toEqualTypeOf<428>() + }) + + it('should match [TOO_MANY_REQUESTS = 429]', () => { + expectTypeOf() + .toHaveProperty('TOO_MANY_REQUESTS') + .toEqualTypeOf<429>() + }) + + it('should match [HEADER_FIELDS_TOO_LARGE = 431]', () => { + expectTypeOf() + .toHaveProperty('HEADER_FIELDS_TOO_LARGE') + .toEqualTypeOf<431>() + }) + + it('should match [UNAVAILABLE_FOR_LEGAL_REASONS = 451]', () => { + expectTypeOf() + .toHaveProperty('UNAVAILABLE_FOR_LEGAL_REASONS') + .toEqualTypeOf<451>() + }) + + it('should match [INTERNAL_SERVER_ERROR = 500]', () => { + expectTypeOf() + .toHaveProperty('INTERNAL_SERVER_ERROR') + .toEqualTypeOf<500>() + }) + + it('should match [NOT_IMPLEMENTED = 501]', () => { + expectTypeOf() + .toHaveProperty('NOT_IMPLEMENTED') + .toEqualTypeOf<501>() + }) + + it('should match [BAD_GATEWAY = 502]', () => { + expectTypeOf() + .toHaveProperty('BAD_GATEWAY') + .toEqualTypeOf<502>() + }) + + it('should match [SERVICE_UNAVAILABLE = 503]', () => { + expectTypeOf() + .toHaveProperty('SERVICE_UNAVAILABLE') + .toEqualTypeOf<503>() + }) + + it('should match [GATEWAY_TIMEOUT = 504]', () => { + expectTypeOf() + .toHaveProperty('GATEWAY_TIMEOUT') + .toEqualTypeOf<504>() + }) + + it('should match [HTTP_VERSION_NOT_SUPPORTED = 505]', () => { + expectTypeOf() + .toHaveProperty('HTTP_VERSION_NOT_SUPPORTED') + .toEqualTypeOf<505>() + }) + + it('should match [VARIANT_NEGOTIATES = 506]', () => { + expectTypeOf() + .toHaveProperty('VARIANT_NEGOTIATES') + .toEqualTypeOf<506>() + }) + + it('should match [INSUFFICIENT_STORAGE = 507]', () => { + expectTypeOf() + .toHaveProperty('INSUFFICIENT_STORAGE') + .toEqualTypeOf<507>() + }) + + it('should match [LOOP_DETECTED = 508]', () => { + expectTypeOf() + .toHaveProperty('LOOP_DETECTED') + .toEqualTypeOf<508>() + }) + + it('should match [NOT_EXTENDED = 510]', () => { + expectTypeOf() + .toHaveProperty('NOT_EXTENDED') + .toEqualTypeOf<510>() + }) + + it('should match [NETWORK_AUTHENTICATION_REQUIRED = 511]', () => { + expectTypeOf() + .toHaveProperty('NETWORK_AUTHENTICATION_REQUIRED') + .toEqualTypeOf<511>() + }) +}) diff --git a/src/enums/__tests__/jwt-type.spec-d.ts b/src/enums/__tests__/jwt-type.spec-d.ts new file mode 100644 index 00000000..64985a8a --- /dev/null +++ b/src/enums/__tests__/jwt-type.spec-d.ts @@ -0,0 +1,26 @@ +/** + * @file Type Tests - JwtType + * @module tutils/enums/tests/unit-d/JwtType + */ + +import type TestSubject from '../jwt-type' + +describe('unit-d:enums/JwtType', () => { + it('should match [ACCESS = "ACCESS"]', () => { + expectTypeOf() + .toHaveProperty('ACCESS') + .toMatchTypeOf<'ACCESS'>() + }) + + it('should match [REFRESH = "REFRESH"]', () => { + expectTypeOf() + .toHaveProperty('REFRESH') + .toMatchTypeOf<'REFRESH'>() + }) + + it('should match [VERIFICATION = "VERIFICATION"]', () => { + expectTypeOf() + .toHaveProperty('VERIFICATION') + .toMatchTypeOf<'VERIFICATION'>() + }) +}) diff --git a/src/enums/__tests__/node-env.spec-d.ts b/src/enums/__tests__/node-env.spec-d.ts new file mode 100644 index 00000000..8ba7c089 --- /dev/null +++ b/src/enums/__tests__/node-env.spec-d.ts @@ -0,0 +1,26 @@ +/** + * @file Type Tests - NodeEnv + * @module tutils/enums/tests/unit-d/NodeEnv + */ + +import type TestSubject from '../node-env' + +describe('unit-d:enums/NodeEnv', () => { + it('should match [DEV = "development"]', () => { + expectTypeOf() + .toHaveProperty('DEV') + .toMatchTypeOf<'development'>() + }) + + it('should match [PROD = "production"]', () => { + expectTypeOf() + .toHaveProperty('PROD') + .toMatchTypeOf<'production'>() + }) + + it('should match [TEST = "test"]', () => { + expectTypeOf() + .toHaveProperty('TEST') + .toMatchTypeOf<'test'>() + }) +}) diff --git a/src/enums/__tests__/project-rule.spec-d.ts b/src/enums/__tests__/project-rule.spec-d.ts new file mode 100644 index 00000000..7759aee8 --- /dev/null +++ b/src/enums/__tests__/project-rule.spec-d.ts @@ -0,0 +1,16 @@ +/** + * @file Type Tests - ProjectRule + * @module tutils/enums/tests/unit-d/ProjectRule + */ + +import type TestSubject from '../project-rule' + +describe('unit-d:enums/ProjectRule', () => { + it('should match [OMIT = 8]', () => { + expectTypeOf().toHaveProperty('OMIT').toEqualTypeOf<0>() + }) + + it('should match [PICK = 1]', () => { + expectTypeOf().toHaveProperty('PICK').toEqualTypeOf<1>() + }) +}) diff --git a/src/enums/__tests__/sort-order.spec-d.ts b/src/enums/__tests__/sort-order.spec-d.ts new file mode 100644 index 00000000..98642e67 --- /dev/null +++ b/src/enums/__tests__/sort-order.spec-d.ts @@ -0,0 +1,20 @@ +/** + * @file Type Tests - SortOrder + * @module tutils/enums/tests/unit-d/SortOrder + */ + +import type TestSubject from '../sort-order' + +describe('unit-d:enums/SortOrder', () => { + it('should match [ASCENDING = 1]', () => { + expectTypeOf() + .toHaveProperty('ASCENDING') + .toEqualTypeOf<1>() + }) + + it('should match [DESCENDING = 1]', () => { + expectTypeOf() + .toHaveProperty('DESCENDING') + .toEqualTypeOf<-1>() + }) +}) diff --git a/src/enums/compare-result.ts b/src/enums/compare-result.ts index 9e9efc6b..0e6a7f4a 100644 --- a/src/enums/compare-result.ts +++ b/src/enums/compare-result.ts @@ -6,9 +6,9 @@ /** * Comparison function return values. * - * Comparison functions are expected to return a negative value if the first - * argument is less than the second argument, zero if they're equal, and a - * positive value otherwise. + * Comparison functions are expected to return a negative number if one argument + * is less than the other, a positive number if an argument is greater than the + * other, or zero (`0`) if the arguments are equal. * * @enum {number} */ diff --git a/src/guards/__tests__/is-app-env.spec-d.ts b/src/guards/__tests__/is-app-env.spec-d.ts new file mode 100644 index 00000000..e16c075b --- /dev/null +++ b/src/guards/__tests__/is-app-env.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - isAppEnv + * @module tutils/guards/tests/unit-d/isAppEnv + */ + +import type { AppEnv } from '#src/enums' +import type testSubject from '../is-app-env' + +describe('unit-d:guards/isAppEnv', () => { + it('should guard AppEnv', () => { + expectTypeOf().guards.toEqualTypeOf() + }) +}) diff --git a/src/guards/__tests__/is-app-env.spec.ts b/src/guards/__tests__/is-app-env.spec.ts index 9e477da1..3dbeecd8 100644 --- a/src/guards/__tests__/is-app-env.spec.ts +++ b/src/guards/__tests__/is-app-env.spec.ts @@ -3,7 +3,7 @@ * @module tutils/guards/tests/unit/isAppEnv */ -import AppEnv from '#src/enums/app-env' +import { AppEnv } from '#src/enums' import type { TestcaseFn } from '#tests/interfaces' import testSubject from '../is-app-env' diff --git a/src/guards/__tests__/is-booleanish.spec-d.ts b/src/guards/__tests__/is-booleanish.spec-d.ts new file mode 100644 index 00000000..56e04230 --- /dev/null +++ b/src/guards/__tests__/is-booleanish.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - isBooleanish + * @module tutils/guards/tests/unit-d/isBooleanish + */ + +import type { Booleanish } from '#src/types' +import type testSubject from '../is-booleanish' + +describe('unit-d:guards/isBooleanish', () => { + it('should guard Booleanish', () => { + expectTypeOf().guards.toEqualTypeOf() + }) +}) diff --git a/src/guards/__tests__/is-empty-string.spec-d.ts b/src/guards/__tests__/is-empty-string.spec-d.ts new file mode 100644 index 00000000..b5b16a1a --- /dev/null +++ b/src/guards/__tests__/is-empty-string.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - isEmptyString + * @module tutils/guards/tests/unit-d/isEmptyString + */ + +import type { EmptyString } from '#src/types' +import type testSubject from '../is-empty-string' + +describe('unit-d:guards/isEmptyString', () => { + it('should guard EmptyString', () => { + expectTypeOf().guards.toEqualTypeOf() + }) +}) diff --git a/src/guards/__tests__/is-empty-value.spec-d.ts b/src/guards/__tests__/is-empty-value.spec-d.ts new file mode 100644 index 00000000..d958e4f9 --- /dev/null +++ b/src/guards/__tests__/is-empty-value.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - isEmptyValue + * @module tutils/guards/tests/unit-d/isEmptyValue + */ + +import type { EmptyValue } from '#src/types' +import type testSubject from '../is-empty-value' + +describe('unit-d:guards/isEmptyValue', () => { + it('should guard EmptyValue', () => { + expectTypeOf().guards.toEqualTypeOf() + }) +}) diff --git a/src/guards/__tests__/is-jwt-type.spec-d.ts b/src/guards/__tests__/is-jwt-type.spec-d.ts new file mode 100644 index 00000000..5c7dae71 --- /dev/null +++ b/src/guards/__tests__/is-jwt-type.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - isJwtType + * @module tutils/guards/tests/unit-d/isJwtType + */ + +import type { JwtType } from '#src/enums' +import type testSubject from '../is-jwt-type' + +describe('unit-d:guards/isJwtType', () => { + it('should guard JwtType', () => { + expectTypeOf().guards.toEqualTypeOf() + }) +}) diff --git a/src/guards/__tests__/is-jwt-type.spec.ts b/src/guards/__tests__/is-jwt-type.spec.ts index b5664d40..b20fbf1c 100644 --- a/src/guards/__tests__/is-jwt-type.spec.ts +++ b/src/guards/__tests__/is-jwt-type.spec.ts @@ -3,7 +3,7 @@ * @module tutils/guards/tests/unit/isJwtType */ -import JwtType from '#src/enums/jwt-type' +import { JwtType } from '#src/enums' import type { TestcaseFn } from '#tests/interfaces' import testSubject from '../is-jwt-type' diff --git a/src/guards/__tests__/is-nil.spec-d.ts b/src/guards/__tests__/is-nil.spec-d.ts new file mode 100644 index 00000000..84f63717 --- /dev/null +++ b/src/guards/__tests__/is-nil.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - isNIL + * @module tutils/guards/tests/unit-d/isNIL + */ + +import type { NIL } from '#src/types' +import type testSubject from '../is-nil' + +describe('unit-d:guards/isNIL', () => { + it('should guard NIL', () => { + expectTypeOf().guards.toEqualTypeOf() + }) +}) diff --git a/src/guards/__tests__/is-node-env.spec-d.ts b/src/guards/__tests__/is-node-env.spec-d.ts new file mode 100644 index 00000000..23bab8c6 --- /dev/null +++ b/src/guards/__tests__/is-node-env.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - isNodeEnv + * @module tutils/guards/tests/unit-d/isNodeEnv + */ + +import type { NodeEnv } from '#src/enums' +import type testSubject from '../is-node-env' + +describe('unit-d:guards/isNodeEnv', () => { + it('should guard NodeEnv', () => { + expectTypeOf().guards.toEqualTypeOf() + }) +}) diff --git a/src/guards/__tests__/is-node-env.spec.ts b/src/guards/__tests__/is-node-env.spec.ts index b90f7391..2406897d 100644 --- a/src/guards/__tests__/is-node-env.spec.ts +++ b/src/guards/__tests__/is-node-env.spec.ts @@ -3,7 +3,7 @@ * @module tutils/guards/tests/unit/isNodeEnv */ -import NodeEnv from '#src/enums/node-env' +import { NodeEnv } from '#src/enums' import type { TestcaseFn } from '#tests/interfaces' import testSubject from '../is-node-env' diff --git a/src/guards/__tests__/is-unix-timestamp.spec-d.ts b/src/guards/__tests__/is-unix-timestamp.spec-d.ts new file mode 100644 index 00000000..0e81ea15 --- /dev/null +++ b/src/guards/__tests__/is-unix-timestamp.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - isUnixTimestamp + * @module tutils/guards/tests/unit-d/isUnixTimestamp + */ + +import type { TimestampUnix } from '#src/types' +import type testSubject from '../is-unix-timestamp' + +describe('unit-d:guards/isUnixTimestamp', () => { + it('should guard TimestampUnix', () => { + expectTypeOf().guards.toEqualTypeOf() + }) +}) diff --git a/src/interfaces/__tests__/map-like.spec-d.ts b/src/interfaces/__tests__/map-like.spec-d.ts new file mode 100644 index 00000000..4cdc56c1 --- /dev/null +++ b/src/interfaces/__tests__/map-like.spec-d.ts @@ -0,0 +1,12 @@ +/** + * @file Type Tests - MapLike + * @module tutils/interfaces/tests/unit-d/MapLike + */ + +import type TestSubject from '../map-like' + +describe('unit-d:interfaces/MapLike', () => { + it('should be a generic', () => { + expectTypeOf[string]>().toBeString() + }) +}) diff --git a/src/types/__tests__/any.spec-d.ts b/src/types/__tests__/any.spec-d.ts new file mode 100644 index 00000000..d0af7034 --- /dev/null +++ b/src/types/__tests__/any.spec-d.ts @@ -0,0 +1,12 @@ +/** + * @file Type Tests - ANY + * @module tutils/types/tests/unit-d/ANY + */ + +import type TestSubject from '../any' + +describe('unit-d:types/ANY', () => { + it('should equal type of any', () => { + expectTypeOf().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/booleanish.spec-d.ts b/src/types/__tests__/booleanish.spec-d.ts new file mode 100644 index 00000000..797f1eb7 --- /dev/null +++ b/src/types/__tests__/booleanish.spec-d.ts @@ -0,0 +1,20 @@ +/** + * @file Type Tests - Booleanish + * @module tutils/types/tests/unit-d/Booleanish + */ + +import type TestSubject from '../booleanish' + +describe('unit-d:types/Booleanish', () => { + it('should extract boolean', () => { + expectTypeOf().extract().toBeBoolean() + }) + + it('should extract "false"', () => { + expectTypeOf().extract<'false'>().toEqualTypeOf<'false'>() + }) + + it('should extract "true"', () => { + expectTypeOf().extract<'true'>().toEqualTypeOf<'true'>() + }) +}) diff --git a/src/types/__tests__/built-in.spec-d.ts b/src/types/__tests__/built-in.spec-d.ts new file mode 100644 index 00000000..24f6ac25 --- /dev/null +++ b/src/types/__tests__/built-in.spec-d.ts @@ -0,0 +1,29 @@ +/** + * @file Type Tests - BuiltIn + * @module tutils/types/tests/unit-d/BuiltIn + */ + +import type TestSubject from '../built-in' +import type Primitive from '../primitive' + +describe('unit-d:types/BuiltIn', () => { + it('should extract Date', () => { + expectTypeOf().extract().toEqualTypeOf() + }) + + it('should extract Error', () => { + expectTypeOf().extract().toEqualTypeOf() + }) + + it('should extract Function', () => { + expectTypeOf().extract().toEqualTypeOf() + }) + + it('should extract Primitive', () => { + expectTypeOf().extract().toEqualTypeOf() + }) + + it('should extract RegExp', () => { + expectTypeOf().extract().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/class.spec-d.ts b/src/types/__tests__/class.spec-d.ts new file mode 100644 index 00000000..57437889 --- /dev/null +++ b/src/types/__tests__/class.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - Class + * @module tutils/types/tests/unit-d/Class + */ + +import Person from '#fixtures/person' +import type TestSubject from '../class' + +describe('unit-d:types/Class', () => { + it('should match class declaration', () => { + assertType>(Person) + }) +}) diff --git a/src/types/__tests__/comparison-operator.spec-d.ts b/src/types/__tests__/comparison-operator.spec-d.ts new file mode 100644 index 00000000..778bbc31 --- /dev/null +++ b/src/types/__tests__/comparison-operator.spec-d.ts @@ -0,0 +1,32 @@ +/** + * @file Type Tests - ComparisonOperator + * @module tutils/types/tests/unit-d/ComparisonOperator + */ + +import type TestSubject from '../comparison-operator' + +describe('unit-d:types/ComparisonOperator', () => { + it('should extract "!="', () => { + expectTypeOf().extract<'!='>().toBeString() + }) + + it('should extract "<"', () => { + expectTypeOf().extract<'<'>().toBeString() + }) + + it('should extract "<="', () => { + expectTypeOf().extract<'<='>().toBeString() + }) + + it('should extract "="', () => { + expectTypeOf().extract<'='>().toBeString() + }) + + it('should extract ">"', () => { + expectTypeOf().extract<'>'>().toBeString() + }) + + it('should extract ">="', () => { + expectTypeOf().extract<'>='>().toBeString() + }) +}) diff --git a/src/types/__tests__/constructor.spec-d.ts b/src/types/__tests__/constructor.spec-d.ts new file mode 100644 index 00000000..58e68c6c --- /dev/null +++ b/src/types/__tests__/constructor.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - Constructor + * @module tutils/types/tests/unit-d/Constructor + */ + +import Person from '#fixtures/person' +import type TestSubject from '../constructor' + +describe('unit-d:types/Constructor', () => { + it('should match class declaration', () => { + assertType>(Person) + }) +}) diff --git a/src/types/__tests__/continuous-value.spec-d.ts b/src/types/__tests__/continuous-value.spec-d.ts new file mode 100644 index 00000000..1079df23 --- /dev/null +++ b/src/types/__tests__/continuous-value.spec-d.ts @@ -0,0 +1,16 @@ +/** + * @file Type Tests - ContinuousValue + * @module tutils/types/tests/unit-d/ContinuousValue + */ + +import type TestSubject from '../continuous-value' + +describe('unit-d:types/ContinuousValue', () => { + it('should extract Date', () => { + expectTypeOf().extract().toEqualTypeOf() + }) + + it('should extract number', () => { + expectTypeOf().extract().toBeNumber() + }) +}) diff --git a/src/types/__tests__/empty-string.spec-d.ts b/src/types/__tests__/empty-string.spec-d.ts new file mode 100644 index 00000000..2c64676a --- /dev/null +++ b/src/types/__tests__/empty-string.spec-d.ts @@ -0,0 +1,12 @@ +/** + * @file Type Tests - EmptyString + * @module tutils/types/tests/unit-d/EmptyString + */ + +import type TestSubject from '../empty-string' + +describe('unit-d:types/EmptyString', () => { + it('should equal type of ""', () => { + expectTypeOf().toEqualTypeOf<''>() + }) +}) diff --git a/src/types/__tests__/empty-value.spec-d.ts b/src/types/__tests__/empty-value.spec-d.ts new file mode 100644 index 00000000..b3b775c2 --- /dev/null +++ b/src/types/__tests__/empty-value.spec-d.ts @@ -0,0 +1,20 @@ +/** + * @file Type Tests - EmptyValue + * @module tutils/types/tests/unit-d/EmptyValue + */ + +import type EmptyString from '../empty-string' +import type TestSubject from '../empty-value' +import type NIL from '../nil' + +describe('unit-d:types/EmptyValue', () => { + it('should extract EmptyString', () => { + expectTypeOf() + .extract() + .toEqualTypeOf() + }) + + it('should extract NIL', () => { + expectTypeOf().extract().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/exact-optional-property-types.spec-d.ts b/src/types/__tests__/exact-optional-property-types.spec-d.ts new file mode 100644 index 00000000..7859e11f --- /dev/null +++ b/src/types/__tests__/exact-optional-property-types.spec-d.ts @@ -0,0 +1,16 @@ +/** + * @file Type Tests - ExactOptionalPropertyTypes + * @module tutils/types/tests/unit-d/ExactOptionalPropertyTypes + */ + +import type TestSubject from '../exact-optional-property-types' + +describe('unit-d:types/ExactOptionalPropertyTypes', () => { + it('should remove undefined from optional properties in T', () => { + // Arrange + type T = { [x: string]: string | undefined } + + // Expect + expectTypeOf>().toEqualTypeOf<{ [x: string]: string }>() + }) +}) diff --git a/src/types/__tests__/fixme.spec-d.ts b/src/types/__tests__/fixme.spec-d.ts new file mode 100644 index 00000000..21dcb4ac --- /dev/null +++ b/src/types/__tests__/fixme.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - FIXME + * @module tutils/types/tests/unit-d/FIXME + */ + +import type ANY from '../any' +import type TestSubject from '../fixme' + +describe('unit-d:types/FIXME', () => { + it('should equal type of ANY', () => { + expectTypeOf().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/index-signature.spec-d.ts b/src/types/__tests__/index-signature.spec-d.ts new file mode 100644 index 00000000..96a8c36c --- /dev/null +++ b/src/types/__tests__/index-signature.spec-d.ts @@ -0,0 +1,20 @@ +/** + * @file Type Tests - IndexSignature + * @module tutils/types/tests/unit-d/IndexSignature + */ + +import type TestSubject from '../index-signature' + +describe('unit-d:types/IndexSignature', () => { + it('should extract number', () => { + expectTypeOf().extract().toBeNumber() + }) + + it('should extract string', () => { + expectTypeOf().extract().toBeString() + }) + + it('should extract symbol', () => { + expectTypeOf().extract().toBeSymbol() + }) +}) diff --git a/src/types/__tests__/is-tuple.spec-d.ts b/src/types/__tests__/is-tuple.spec-d.ts new file mode 100644 index 00000000..712e7d72 --- /dev/null +++ b/src/types/__tests__/is-tuple.spec-d.ts @@ -0,0 +1,17 @@ +/** + * @file Type Tests - IsTuple + * @module tutils/types/tests/unit-d/IsTuple + */ + +import type BuiltIn from '../built-in' +import type TestSubject from '../is-tuple' + +describe('unit-d:types/IsTuple', () => { + it('should equal T if T is a tuple', () => { + expectTypeOf>().toBeArray() + }) + + it('should equal never if T is not a tuple', () => { + expectTypeOf>().toBeNever() + }) +}) diff --git a/src/types/__tests__/join.spec-d.ts b/src/types/__tests__/join.spec-d.ts new file mode 100644 index 00000000..17d1cdca --- /dev/null +++ b/src/types/__tests__/join.spec-d.ts @@ -0,0 +1,17 @@ +/** + * @file Type Tests - Join + * @module tutils/types/tests/unit-d/Join + */ + +import type TestSubject from '../join' + +describe('unit-d:types/Join', () => { + it('should concatenate elements in Arr using Delimiter', () => { + // Arrange + type Arr = ['foo', 0, 'bar'] + type Delimiter = '.' + + // Expect + expectTypeOf>().toEqualTypeOf<'foo.0.bar'>() + }) +}) diff --git a/src/types/__tests__/json-array.spec-d.ts b/src/types/__tests__/json-array.spec-d.ts new file mode 100644 index 00000000..e86dbc25 --- /dev/null +++ b/src/types/__tests__/json-array.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - JsonArray + * @module tutils/types/tests/unit-d/JsonArray + */ + +import type TestSubject from '../json-array' +import type JsonValue from '../json-value' + +describe('unit-d:types/JsonArray', () => { + it('should equal JsonValue[]', () => { + expectTypeOf().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/json-object.spec-d.ts b/src/types/__tests__/json-object.spec-d.ts new file mode 100644 index 00000000..940620ec --- /dev/null +++ b/src/types/__tests__/json-object.spec-d.ts @@ -0,0 +1,17 @@ +/** + * @file Type Tests - JsonObject + * @module tutils/types/tests/unit-d/JsonObject + */ + +import type TestSubject from '../json-object' +import type JsonValue from '../json-value' + +describe('unit-d:types/JsonObject', () => { + it('should have keys of type string', () => { + expectTypeOf().toBeString() + }) + + it('should have properties of type JsonValue', () => { + expectTypeOf().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/json-primitive.spec-d.ts b/src/types/__tests__/json-primitive.spec-d.ts new file mode 100644 index 00000000..df52445a --- /dev/null +++ b/src/types/__tests__/json-primitive.spec-d.ts @@ -0,0 +1,24 @@ +/** + * @file Type Tests - JsonPrimitive + * @module tutils/types/tests/unit-d/JsonPrimitive + */ + +import type TestSubject from '../json-primitive' + +describe('unit-d:types/JsonPrimitive', () => { + it('should extract boolean', () => { + expectTypeOf().extract().toBeBoolean() + }) + + it('should extract number', () => { + expectTypeOf().extract().toBeNumber() + }) + + it('should extract string', () => { + expectTypeOf().extract().toBeString() + }) + + it('should extract null', () => { + expectTypeOf().extract().toBeNull() + }) +}) diff --git a/src/types/__tests__/json-value.spec-d.ts b/src/types/__tests__/json-value.spec-d.ts new file mode 100644 index 00000000..8310fcf6 --- /dev/null +++ b/src/types/__tests__/json-value.spec-d.ts @@ -0,0 +1,27 @@ +/** + * @file Type Tests - JsonValue + * @module tutils/types/tests/unit-d/JsonValue + */ + +import type JsonArray from '../json-array' +import type JsonObject from '../json-object' +import type JsonPrimitive from '../json-primitive' +import type TestSubject from '../json-value' + +describe('unit-d:types/JsonValue', () => { + it('should extract JsonArray', () => { + expectTypeOf().extract().toEqualTypeOf() + }) + + it('should extract JsonObject', () => { + expectTypeOf() + .extract() + .toEqualTypeOf() + }) + + it('should extract JsonPrimitive', () => { + expectTypeOf() + .extract() + .toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/jsonifiable-array.spec-d.ts b/src/types/__tests__/jsonifiable-array.spec-d.ts new file mode 100644 index 00000000..eb6ebbe1 --- /dev/null +++ b/src/types/__tests__/jsonifiable-array.spec-d.ts @@ -0,0 +1,13 @@ +/** + * @file Type Tests - JsonifiableArray + * @module tutils/types/tests/unit-d/JsonifiableArray + */ + +import type Jsonifiable from '../jsonifiable' +import type TestSubject from '../jsonifiable-array' + +describe('unit-d:types/JsonifiableArray', () => { + it('should equal readonly Jsonifiable[]', () => { + expectTypeOf().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/jsonifiable-instance.spec-d.ts b/src/types/__tests__/jsonifiable-instance.spec-d.ts new file mode 100644 index 00000000..a3f9d43b --- /dev/null +++ b/src/types/__tests__/jsonifiable-instance.spec-d.ts @@ -0,0 +1,15 @@ +/** + * @file Type Tests - JsonifiableInstance + * @module tutils/types/tests/unit-d/JsonifiableInstance + */ + +import type Jsonifiable from '../jsonifiable' +import type TestSubject from '../jsonifiable-instance' + +describe('unit-d:types/JsonifiableInstance', () => { + it('should match [toJSON(): Jsonifiable]', () => { + expectTypeOf() + .toHaveProperty('toJSON') + .toEqualTypeOf<() => Jsonifiable>() + }) +}) diff --git a/src/types/__tests__/jsonifiable-object.spec-d.ts b/src/types/__tests__/jsonifiable-object.spec-d.ts new file mode 100644 index 00000000..305260b9 --- /dev/null +++ b/src/types/__tests__/jsonifiable-object.spec-d.ts @@ -0,0 +1,17 @@ +/** + * @file Type Tests - JsonifiableObject + * @module tutils/types/tests/unit-d/JsonifiableObject + */ + +import type Jsonifiable from '../jsonifiable' +import type TestSubject from '../jsonifiable-object' + +describe('unit-d:types/JsonifiableObject', () => { + it('should have keys of type string', () => { + expectTypeOf().toBeString() + }) + + it('should have properties of type Jsonifiable | undefined', () => { + expectTypeOf().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/jsonifiable.spec-d.ts b/src/types/__tests__/jsonifiable.spec-d.ts new file mode 100644 index 00000000..dd9672a1 --- /dev/null +++ b/src/types/__tests__/jsonifiable.spec-d.ts @@ -0,0 +1,36 @@ +/** + * @file Type Tests - Jsonifiable + * @module tutils/types/tests/unit-d/Jsonifiable + */ + +import type JsonPrimitive from '../json-primitive' +import type TestSubject from '../jsonifiable' +import type JsonifiableArray from '../jsonifiable-array' +import type JsonifiableInstance from '../jsonifiable-instance' +import type JsonifiableObject from '../jsonifiable-object' + +describe('unit-d:types/Jsonifiable', () => { + it('should extract JsonifiableArray', () => { + expectTypeOf() + .extract() + .toEqualTypeOf() + }) + + it('should extract JsonifiableInstance', () => { + expectTypeOf() + .extract() + .toEqualTypeOf() + }) + + it('should extract JsonifiableObject', () => { + expectTypeOf() + .extract() + .toEqualTypeOf() + }) + + it('should extract JsonPrimitive', () => { + expectTypeOf() + .extract() + .toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/keys-optional.spec-d.ts b/src/types/__tests__/keys-optional.spec-d.ts new file mode 100644 index 00000000..132d5496 --- /dev/null +++ b/src/types/__tests__/keys-optional.spec-d.ts @@ -0,0 +1,16 @@ +/** + * @file Type Tests - KeysOptional + * @module tutils/types/tests/unit-d/KeysOptional + */ + +import type TestSubject from '../keys-optional' + +describe('unit-d:types/KeysOptional', () => { + it('should extract optional keys from T', () => { + // Arrange + type T = { display_name?: string; username: string } + + // Expect + expectTypeOf>().toEqualTypeOf<'display_name'>() + }) +}) diff --git a/src/types/__tests__/keys-required.spec-d.ts b/src/types/__tests__/keys-required.spec-d.ts new file mode 100644 index 00000000..7ae93efc --- /dev/null +++ b/src/types/__tests__/keys-required.spec-d.ts @@ -0,0 +1,16 @@ +/** + * @file Type Tests - KeysRequired + * @module tutils/types/tests/unit-d/KeysRequired + */ + +import type TestSubject from '../keys-required' + +describe('unit-d:types/KeysRequired', () => { + it('should extract required keys from T', () => { + // Arrange + type T = { display_name?: string; username: string } + + // Expect + expectTypeOf>().toEqualTypeOf<'username'>() + }) +}) diff --git a/src/types/__tests__/literal-union.spec-d.ts b/src/types/__tests__/literal-union.spec-d.ts new file mode 100644 index 00000000..6eeb6c91 --- /dev/null +++ b/src/types/__tests__/literal-union.spec-d.ts @@ -0,0 +1,21 @@ +/** + * @file Type Tests - LiteralUnion + * @module tutils/types/tests/unit-d/LiteralUnion + */ + +import type TestSubject from '../literal-union' + +describe('unit-d:types/LiteralUnion', () => { + type L = 'node' | 'npm' | 'yarn' + type P = string + + it('should extract L', () => { + expectTypeOf>().extract().toEqualTypeOf() + }) + + it('should extract P & Record', () => { + expectTypeOf>() + .extract

>() + .toEqualTypeOf

>() + }) +}) diff --git a/src/types/__tests__/nil.spec-d.ts b/src/types/__tests__/nil.spec-d.ts new file mode 100644 index 00000000..79e7bd05 --- /dev/null +++ b/src/types/__tests__/nil.spec-d.ts @@ -0,0 +1,16 @@ +/** + * @file Type Tests - NIL + * @module tutils/types/tests/unit-d/NIL + */ + +import type TestSubject from '../nil' + +describe('unit-d:types/NIL', () => { + it('should extract null', () => { + expectTypeOf().extract().toBeNull() + }) + + it('should extract undefined', () => { + expectTypeOf().extract().toBeUndefined() + }) +}) diff --git a/src/types/__tests__/nilable.spec-d.ts b/src/types/__tests__/nilable.spec-d.ts new file mode 100644 index 00000000..2c63c207 --- /dev/null +++ b/src/types/__tests__/nilable.spec-d.ts @@ -0,0 +1,17 @@ +/** + * @file Type Tests - Nilable + * @module tutils/types/tests/unit-d/Nilable + */ + +import type NIL from '../nil' +import type TestSubject from '../nilable' + +describe('unit-d:types/Nilable', () => { + it('should extract NIL', () => { + expectTypeOf>().extract().toEqualTypeOf() + }) + + it('should extract T', () => { + expectTypeOf>().extract().toBeString() + }) +}) diff --git a/src/types/__tests__/nullable.spec-d.ts b/src/types/__tests__/nullable.spec-d.ts new file mode 100644 index 00000000..cf34b802 --- /dev/null +++ b/src/types/__tests__/nullable.spec-d.ts @@ -0,0 +1,16 @@ +/** + * @file Type Tests - Nullable + * @module tutils/types/tests/unit-d/Nullable + */ + +import type TestSubject from '../nullable' + +describe('unit-d:types/Nullable', () => { + it('should extract T', () => { + expectTypeOf>().extract().toBeString() + }) + + it('should extract null', () => { + expectTypeOf>().extract().toBeNull() + }) +}) diff --git a/src/types/__tests__/number-like.spec-d.ts b/src/types/__tests__/number-like.spec-d.ts new file mode 100644 index 00000000..693c0f89 --- /dev/null +++ b/src/types/__tests__/number-like.spec-d.ts @@ -0,0 +1,17 @@ +/** + * @file Type Tests - NumberLike + * @module tutils/types/tests/unit-d/NumberLike + */ + +import type TestSubject from '../number-like' +import type Numeric from '../numeric' + +describe('unit-d:types/NumberLike', () => { + it('should extract Numeric', () => { + expectTypeOf().extract().toEqualTypeOf() + }) + + it('should extract number', () => { + expectTypeOf().extract().toBeNumber() + }) +}) diff --git a/src/types/__tests__/numeric.spec-d.ts b/src/types/__tests__/numeric.spec-d.ts new file mode 100644 index 00000000..28b188fa --- /dev/null +++ b/src/types/__tests__/numeric.spec-d.ts @@ -0,0 +1,16 @@ +/** + * @file Type Tests - Numeric + * @module tutils/types/tests/unit-d/Numeric + */ + +import type TestSubject from '../numeric' + +describe('unit-d:types/Numeric', () => { + it('should allow value that is stringified number', () => { + assertType(`${faker.number.int()}`) + }) + + it('should not allow value that is not stringified number', () => { + expectTypeOf().not.toEqualTypeOf(faker.string.uuid()) + }) +}) diff --git a/src/types/__tests__/object-empty.spec-d.ts b/src/types/__tests__/object-empty.spec-d.ts new file mode 100644 index 00000000..65991897 --- /dev/null +++ b/src/types/__tests__/object-empty.spec-d.ts @@ -0,0 +1,16 @@ +/** + * @file Type Tests - ObjectEmpty + * @module tutils/types/tests/unit-d/ObjectEmpty + */ + +import type TestSubject from '../object-empty' + +describe('unit-d:types/ObjectEmpty', () => { + it('should have keys of type string', () => { + expectTypeOf().toBeString() + }) + + it('should have properties of type never', () => { + expectTypeOf().toBeNever() + }) +}) diff --git a/src/types/__tests__/object-plain.spec-d.ts b/src/types/__tests__/object-plain.spec-d.ts new file mode 100644 index 00000000..e531549d --- /dev/null +++ b/src/types/__tests__/object-plain.spec-d.ts @@ -0,0 +1,17 @@ +/** + * @file Type Tests - ObjectPlain + * @module tutils/types/tests/unit-d/ObjectPlain + */ + +import type IndexSignature from '../index-signature' +import type TestSubject from '../object-plain' + +describe('unit-d:types/ObjectPlain', () => { + it('should have keys of type IndexSignature', () => { + expectTypeOf().toEqualTypeOf() + }) + + it('should have properties of type any', () => { + expectTypeOf().toBeAny() + }) +}) diff --git a/src/types/__tests__/object-unknown.spec-d.ts b/src/types/__tests__/object-unknown.spec-d.ts new file mode 100644 index 00000000..30b33323 --- /dev/null +++ b/src/types/__tests__/object-unknown.spec-d.ts @@ -0,0 +1,17 @@ +/** + * @file Type Tests - ObjectUnknown + * @module tutils/types/tests/unit-d/ObjectUnknown + */ + +import type IndexSignature from '../index-signature' +import type TestSubject from '../object-unknown' + +describe('unit-d:types/ObjectUnknown', () => { + it('should have keys of type IndexSignature', () => { + expectTypeOf().toEqualTypeOf() + }) + + it('should have properties of type unknown', () => { + expectTypeOf().toBeUnknown() + }) +}) diff --git a/src/types/__tests__/one-or-many.spec-d.ts b/src/types/__tests__/one-or-many.spec-d.ts new file mode 100644 index 00000000..a3edcb50 --- /dev/null +++ b/src/types/__tests__/one-or-many.spec-d.ts @@ -0,0 +1,18 @@ +/** + * @file Type Tests - OneOrMany + * @module tutils/types/tests/unit-d/OneOrMany + */ + +import type TestSubject from '../one-or-many' + +describe('unit-d:types/OneOrMany', () => { + type T = string + + it('should extract T', () => { + expectTypeOf>().extract().toEqualTypeOf() + }) + + it('should extract T[]', () => { + expectTypeOf>().extract().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/opaque.spec-d.ts b/src/types/__tests__/opaque.spec-d.ts new file mode 100644 index 00000000..afc9b8cd --- /dev/null +++ b/src/types/__tests__/opaque.spec-d.ts @@ -0,0 +1,23 @@ +/** + * @file Type Tests - Opaque + * @module tutils/types/tests/unit-d/Opaque + */ + +import type TestSubject from '../opaque' + +describe('unit-d:types/Opaque', () => { + type B = number + type T = 'account-number' + + it('should be assignable to type of B', () => { + expectTypeOf>().toMatchTypeOf() + }) + + it('should not match opaque type with same base and different token', () => { + // Arrange + type T2 = 'account-balance' + + // Expect + expectTypeOf>().not.toMatchTypeOf>() + }) +}) diff --git a/src/types/__tests__/or-lowercase.spec-d.ts b/src/types/__tests__/or-lowercase.spec-d.ts new file mode 100644 index 00000000..ca314765 --- /dev/null +++ b/src/types/__tests__/or-lowercase.spec-d.ts @@ -0,0 +1,20 @@ +/** + * @file Type Tests - OrLowercase + * @module tutils/types/tests/unit-d/OrLowercase + */ + +import type TestSubject from '../or-lowercase' + +describe('unit-d:types/OrLowercase', () => { + type T = 'CRLF' | 'LF' + + it('should extract Lowercase', () => { + expectTypeOf>() + .extract>() + .toEqualTypeOf>() + }) + + it('should extract T', () => { + expectTypeOf>().extract().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/or-uppercase.spec-d.ts b/src/types/__tests__/or-uppercase.spec-d.ts new file mode 100644 index 00000000..22839cd4 --- /dev/null +++ b/src/types/__tests__/or-uppercase.spec-d.ts @@ -0,0 +1,20 @@ +/** + * @file Type Tests - OrUppercase + * @module tutils/types/tests/unit-d/OrUppercase + */ + +import type TestSubject from '../or-uppercase' + +describe('unit-d:types/OrUppercase', () => { + type T = 'crlf' | 'lf' + + it('should extract T', () => { + expectTypeOf>().extract().toEqualTypeOf() + }) + + it('should extract Uppercase', () => { + expectTypeOf>() + .extract>() + .toEqualTypeOf>() + }) +}) diff --git a/src/types/__tests__/overwrite.spec-d.ts b/src/types/__tests__/overwrite.spec-d.ts new file mode 100644 index 00000000..0e36c415 --- /dev/null +++ b/src/types/__tests__/overwrite.spec-d.ts @@ -0,0 +1,19 @@ +/** + * @file Type Tests - Overwrite + * @module tutils/types/tests/unit-d/Overwrite + */ + +import type TestSubject from '../overwrite' + +describe('unit-d:types/Overwrite', () => { + type U = { name: string; uid: string } + type D = { uid: number } + + it('should replace existing properties in U with properties in D', () => { + // Arrange + type Expected = { name: string; uid: number } + + // Expect + expectTypeOf>().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/path-n.spec-d.ts b/src/types/__tests__/path-n.spec-d.ts new file mode 100644 index 00000000..2408a76c --- /dev/null +++ b/src/types/__tests__/path-n.spec-d.ts @@ -0,0 +1,18 @@ +/** + * @file Type Tests - PathN + * @module tutils/types/tests/unit-d/PathN + */ + +import type TestSubject from '../path-n' + +describe('unit-d:types/PathN', () => { + it('should extract properties nested under T[K]', () => { + // Arrange + type T = { foo: { bar: { data: string } } } + type K = 'foo' + type Expected = `${K}.bar.data` | `${K}.bar` + + // Expect + expectTypeOf>().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/path-nt.spec-d.ts b/src/types/__tests__/path-nt.spec-d.ts new file mode 100644 index 00000000..e019b96e --- /dev/null +++ b/src/types/__tests__/path-nt.spec-d.ts @@ -0,0 +1,23 @@ +/** + * @file Type Tests - PathNT + * @module tutils/types/tests/unit-d/PathNT + */ + +import type PathN from '../path-n' +import type TestSubject from '../path-nt' + +describe('unit-d:types/PathNT', () => { + type T = { foo: { data: string } } + + it('should extract PathN', () => { + // Arrange + type Extract = PathN + + // Expect + expectTypeOf>().extract().toEqualTypeOf() + }) + + it('should extract keyof T', () => { + expectTypeOf>().extract().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/path-value.spec-d.ts b/src/types/__tests__/path-value.spec-d.ts new file mode 100644 index 00000000..e8d80ee4 --- /dev/null +++ b/src/types/__tests__/path-value.spec-d.ts @@ -0,0 +1,17 @@ +/** + * @file Type Tests - PathValue + * @module tutils/types/tests/unit-d/PathValue + */ + +import type TestSubject from '../path-value' + +describe('unit-d:types/PathValue', () => { + it('should extract type of value at T[P]', () => { + // Arrange + type T = { foo: { bar: { data: string } } } + type P = 'foo.bar.data' | 'foo.bar' + + // Expect + expectTypeOf>().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/path.spec-d.ts b/src/types/__tests__/path.spec-d.ts new file mode 100644 index 00000000..091ed09d --- /dev/null +++ b/src/types/__tests__/path.spec-d.ts @@ -0,0 +1,17 @@ +/** + * @file Type Tests - Path + * @module tutils/types/tests/unit-d/Path + */ + +import type TestSubject from '../path' + +describe('unit-d:types/Path', () => { + it('should extract nested and top-level properties of T', () => { + // Arrange + type T = { foo: { bar: { data: string } } } + type Expected = 'foo.bar.data' | 'foo.bar' | 'foo' + + // Expect + expectTypeOf>().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/predicate.spec-d.ts b/src/types/__tests__/predicate.spec-d.ts new file mode 100644 index 00000000..75be8d99 --- /dev/null +++ b/src/types/__tests__/predicate.spec-d.ts @@ -0,0 +1,18 @@ +/** + * @file Type Tests - Predicate + * @module tutils/types/tests/unit-d/Predicate + */ + +import type TestSubject from '../predicate' + +describe('unit-d:types/Predicate', () => { + type T = number + + it('should be callable with [T, number, T[]]', () => { + expectTypeOf>().parameters.toEqualTypeOf<[T, number, T[]]>() + }) + + it('should return boolean', () => { + expectTypeOf>().returns.toBeBoolean() + }) +}) diff --git a/src/types/__tests__/primitive.spec-d.ts b/src/types/__tests__/primitive.spec-d.ts new file mode 100644 index 00000000..4687f1dd --- /dev/null +++ b/src/types/__tests__/primitive.spec-d.ts @@ -0,0 +1,27 @@ +/** + * @file Type Tests - Primitive + * @module tutils/types/tests/unit-d/Primitive + */ + +import type JsonPrimitive from '../json-primitive' +import type TestSubject from '../primitive' + +describe('unit-d:types/Primitive', () => { + it('should extract JsonPrimitive', () => { + expectTypeOf() + .extract() + .toEqualTypeOf() + }) + + it('should extract bigint', () => { + expectTypeOf().extract().toEqualTypeOf() + }) + + it('should extract symbol', () => { + expectTypeOf().extract().toBeSymbol() + }) + + it('should extract undefined', () => { + expectTypeOf().extract().toBeUndefined() + }) +}) diff --git a/src/types/__tests__/promisable.spec-d.ts b/src/types/__tests__/promisable.spec-d.ts new file mode 100644 index 00000000..1cdfcfcc --- /dev/null +++ b/src/types/__tests__/promisable.spec-d.ts @@ -0,0 +1,20 @@ +/** + * @file Type Tests - Promisable + * @module tutils/types/tests/unit-d/Promisable + */ + +import type TestSubject from '../promisable' + +describe('unit-d:types/Promisable', () => { + type T = string + + it('should extract PromiseLike', () => { + expectTypeOf>() + .extract>() + .toEqualTypeOf>() + }) + + it('should extract T', () => { + expectTypeOf>().extract().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/simplify.spec-d.ts b/src/types/__tests__/simplify.spec-d.ts new file mode 100644 index 00000000..8d7f1b8d --- /dev/null +++ b/src/types/__tests__/simplify.spec-d.ts @@ -0,0 +1,15 @@ +/** + * @file Type Tests - Simplify + * @module tutils/types/tests/unit-d/Simplify + */ + +import type { IOrderedPair, TOrderedPair } from '#fixtures/ordered-pair' +import type ObjectUnknown from '../object-unknown' +import type TestSubject from '../simplify' + +describe('unit-d:types/Simplify', () => { + it('should simplify complex type', () => { + expectTypeOf>().toEqualTypeOf() + expectTypeOf>().toMatchTypeOf() + }) +}) diff --git a/src/types/__tests__/split.spec-d.ts b/src/types/__tests__/split.spec-d.ts new file mode 100644 index 00000000..a62c68fa --- /dev/null +++ b/src/types/__tests__/split.spec-d.ts @@ -0,0 +1,18 @@ +/** + * @file Type Tests - Split + * @module tutils/types/tests/unit-d/Split + */ + +import type TestSubject from '../split' + +describe('unit-d:types/Split', () => { + it('should split Str using Delimiter', () => { + // Arrange + type Str = 'foo.0.bar' + type Delimiter = '.' + type Expected = ['foo', '0', 'bar'] + + // Expect + expectTypeOf>().toEqualTypeOf() + }) +}) diff --git a/src/types/__tests__/stringafiable.spec-d.ts b/src/types/__tests__/stringafiable.spec-d.ts new file mode 100644 index 00000000..3fe99892 --- /dev/null +++ b/src/types/__tests__/stringafiable.spec-d.ts @@ -0,0 +1,14 @@ +/** + * @file Type Tests - Stringafiable + * @module tutils/types/tests/unit-d/Stringafiable + */ + +import type TestSubject from '../stringafiable' + +describe('unit-d:types/Stringafiable', () => { + it('should match [toString(): string]', () => { + expectTypeOf() + .toHaveProperty('toString') + .toEqualTypeOf<() => string>() + }) +}) diff --git a/src/types/__tests__/timestamp-unix.spec-d.ts b/src/types/__tests__/timestamp-unix.spec-d.ts new file mode 100644 index 00000000..f7aab7cd --- /dev/null +++ b/src/types/__tests__/timestamp-unix.spec-d.ts @@ -0,0 +1,12 @@ +/** + * @file Type Tests - TimestampUnix + * @module tutils/types/tests/unit-d/TimestampUnix + */ + +import type TestSubject from '../timestamp-unix' + +describe('unit-d:types/TimestampUnix', () => { + it('should be a number', () => { + expectTypeOf().toBeNumber() + }) +}) diff --git a/src/types/__tests__/typed-array.spec-d.ts b/src/types/__tests__/typed-array.spec-d.ts new file mode 100644 index 00000000..185220cc --- /dev/null +++ b/src/types/__tests__/typed-array.spec-d.ts @@ -0,0 +1,52 @@ +/** + * @file Type Tests - TypedArray + * @module tutils/types/tests/unit-d/TypedArray + */ + +import type TestSubject from '../typed-array' + +describe('unit-d:types/TypedArray', () => { + it('should extract BigInt64Array', () => { + expectTypeOf().extract().toBeObject() + }) + + it('should extract BigUint64Array', () => { + expectTypeOf().extract().toBeObject() + }) + + it('should extract Float32Array', () => { + expectTypeOf().extract().toBeObject() + }) + + it('should extract Float64Array', () => { + expectTypeOf().extract().toBeObject() + }) + + it('should extract Int8Array', () => { + expectTypeOf().extract().toBeObject() + }) + + it('should extract Int16Array', () => { + expectTypeOf().extract().toBeObject() + }) + + it('should extract Int32Array', () => { + expectTypeOf().extract().toBeObject() + }) + + it('should extract Uint8Array', () => { + expectTypeOf().extract().toBeObject() + }) + + it('should extract Uint8ClampedArray', () => { + expectTypeOf().extract().toBeObject() + }) + + it('should extract Uint16Array', () => { + expectTypeOf().extract().toBeObject() + }) + + it('should extract Uint32Array', () => { + expectTypeOf().extract().toBeObject() + }) +}) diff --git a/src/types/class.ts b/src/types/class.ts index bc4912f6..13187377 100644 --- a/src/types/class.ts +++ b/src/types/class.ts @@ -6,7 +6,7 @@ import type Constructor from './constructor' /** - * Matches a [`class` object][1]. + * A [`class`][1]. * * [1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Classes * diff --git a/src/types/constructor.ts b/src/types/constructor.ts index 7be33d9c..dd934621 100644 --- a/src/types/constructor.ts +++ b/src/types/constructor.ts @@ -4,7 +4,7 @@ */ /** - * Matches a [`class` constructor][1]. + * A [`class` constructor][1]. * * [1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Classes/constructor * diff --git a/src/types/exact-optional-property-types.ts b/src/types/exact-optional-property-types.ts index 0c6ec28a..7a11898b 100644 --- a/src/types/exact-optional-property-types.ts +++ b/src/types/exact-optional-property-types.ts @@ -11,6 +11,8 @@ import type ObjectPlain from './object-plain' * This is a workaround for [`Microsoft/TypeScript#46969`][1]. * * [1]: https://github.com/Microsoft/TypeScript/issues/46969 + * + * @template T - Object type */ type ExactOptionalPropertyTypes = { [K in keyof T]: Exclude extends never diff --git a/src/types/fixme.ts b/src/types/fixme.ts index 478adfe3..16a899ba 100644 --- a/src/types/fixme.ts +++ b/src/types/fixme.ts @@ -3,9 +3,11 @@ * @module tutils/types/FIXME */ +import type ANY from './any' + /** * Helper type indicating a type that needs a better type definition. */ -type FIXME = any +type FIXME = ANY export type { FIXME as default } diff --git a/src/types/is-tuple.ts b/src/types/is-tuple.ts index 27e261b0..2eddec89 100644 --- a/src/types/is-tuple.ts +++ b/src/types/is-tuple.ts @@ -8,7 +8,7 @@ * * [1]: https://tutorialsteacher.com/typescript/typescript-tuple * - * @template T - Value type + * @template T - Type to evaluate */ type IsTuple = T extends [infer A] ? T diff --git a/src/types/json-primitive.ts b/src/types/json-primitive.ts index 6176c4ed..b84cc50c 100644 --- a/src/types/json-primitive.ts +++ b/src/types/json-primitive.ts @@ -4,7 +4,7 @@ */ /** - * Type representing any [primitive][1] [JSON value][2]. + * Type representing any [primitive][1] [`JSON` value][2]. * * [1]: https://developer.mozilla.org/docs/Glossary/Primitive * [2]: https://restfulapi.net/json-data-types diff --git a/src/types/jsonifiable-array.ts b/src/types/jsonifiable-array.ts index 8dc68091..b85f8e3d 100644 --- a/src/types/jsonifiable-array.ts +++ b/src/types/jsonifiable-array.ts @@ -6,7 +6,7 @@ import type Jsonifiable from './jsonifiable' /** - * Matches an array whose items can be losslessly converted to JSON. + * An array whose items can be losslessly converted to JSON. * * @see [`Jsonifiable`]({@link ./jsonifiable.ts}) */ diff --git a/src/types/jsonifiable-instance.ts b/src/types/jsonifiable-instance.ts index d9a2b321..70939b09 100644 --- a/src/types/jsonifiable-instance.ts +++ b/src/types/jsonifiable-instance.ts @@ -6,7 +6,7 @@ import type Jsonifiable from './jsonifiable' /** - * Matches an object with a `toJSON` method. + * An object with a `toJSON` method. * * When invoked, the object can be losslessly converted to JSON. * diff --git a/src/types/jsonifiable-object.ts b/src/types/jsonifiable-object.ts index b32f1551..381eb7b0 100644 --- a/src/types/jsonifiable-object.ts +++ b/src/types/jsonifiable-object.ts @@ -6,7 +6,7 @@ import type Jsonifiable from './jsonifiable' /** - * Matches an object that can be losslessly converted to JSON. + * An object that can be losslessly converted to JSON. * * For objects with `toJSON` methods, use [`JsonifiableInstance`][1] instead. * @@ -15,6 +15,6 @@ import type Jsonifiable from './jsonifiable' * * @see [`Jsonifiable`][2] */ -type JsonifiableObject = { [K in string]?: Jsonifiable } +type JsonifiableObject = { [K in string]?: Jsonifiable | undefined } export type { JsonifiableObject as default } diff --git a/src/types/jsonifiable.ts b/src/types/jsonifiable.ts index e29543ff..a2756793 100644 --- a/src/types/jsonifiable.ts +++ b/src/types/jsonifiable.ts @@ -9,7 +9,7 @@ import type JsonifiableInstance from './jsonifiable-instance' import type JsonifiableObject from './jsonifiable-object' /** - * Matches a value that can be losslessly converted to JSON. + * A value that can be losslessly converted to JSON. * * Can be used to type values that are expected to pass `JSON.stringify`. */ diff --git a/src/types/object-empty.ts b/src/types/object-empty.ts index 1a91e060..3b5f16de 100644 --- a/src/types/object-empty.ts +++ b/src/types/object-empty.ts @@ -4,7 +4,7 @@ */ /** - * Type representing any empty object. + * An empty object. */ type ObjectEmpty = Record diff --git a/src/types/object-plain.ts b/src/types/object-plain.ts index 0d996020..26508f4b 100644 --- a/src/types/object-plain.ts +++ b/src/types/object-plain.ts @@ -6,7 +6,7 @@ import type IndexSignature from './index-signature' /** - * Type representing any plain object (`{}`) value. + * A plain object. */ type ObjectPlain = { [Key in IndexSignature]?: any } diff --git a/src/types/object-unknown.ts b/src/types/object-unknown.ts index d42da510..3bbbd470 100644 --- a/src/types/object-unknown.ts +++ b/src/types/object-unknown.ts @@ -6,7 +6,7 @@ import type IndexSignature from './index-signature' /** - * Type representing any object. + * Any object. */ type ObjectUnknown = { [Key in IndexSignature]?: unknown } diff --git a/src/types/opaque.ts b/src/types/opaque.ts index d2189777..8c394437 100644 --- a/src/types/opaque.ts +++ b/src/types/opaque.ts @@ -3,7 +3,10 @@ * @module tutils/types/Opaque */ -declare const tag: unique symbol +/** + * Token symbol for {@linkcode Opaque}. + */ +declare const token: unique symbol /** * Creates an [opaque type][1]. @@ -19,6 +22,6 @@ declare const tag: unique symbol * @template B - Base type * @template T - Type token */ -type Opaque = B & { readonly [tag]: T } +type Opaque = B & { readonly [token]: T } export type { Opaque as default } diff --git a/src/types/overwrite.ts b/src/types/overwrite.ts index 5dd8b407..608400df 100644 --- a/src/types/overwrite.ts +++ b/src/types/overwrite.ts @@ -6,13 +6,13 @@ import type ObjectPlain from './object-plain' /** - * Replaces existing properties in `Obj` with those in `DTO`. + * Replaces existing properties in object `U` with properties in object `D`. * - * @template Obj - Object to update - * @template DTO - Object to update with + * @template U - Object to update + * @template D - Data transfer object */ -type Overwrite = { - [K in keyof Obj]: K extends keyof DTO ? DTO[K] : Obj[K] +type Overwrite = { + [K in keyof U]: K extends keyof D ? D[K] : U[K] } & {} export type { Overwrite as default } diff --git a/src/types/split.ts b/src/types/split.ts index fb5dc8c8..1a425477 100644 --- a/src/types/split.ts +++ b/src/types/split.ts @@ -4,17 +4,17 @@ */ /** - * Constructs a string array by splitting string `S` using delimiter `D`. + * Creates a string array by splitting a string using the given delimiter. * - * @template S - String to split - * @template D - String delimiter + * @template Str - String to split + * @template Delimiter - String delimiter */ -type Split = string extends S +type Split = string extends Str ? string[] - : S extends '' + : Str extends '' ? [] - : S extends `${infer T}${D}${infer U}` - ? [T, ...Split] - : [S] + : Str extends `${infer T}${Delimiter}${infer U}` + ? [T, ...Split] + : [Str] export type { Split as default } diff --git a/tsconfig.json b/tsconfig.json index 27c40673..7c1a47a0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -30,6 +30,7 @@ "noUnusedParameters": false, "outDir": "dist", "paths": { + "#fixtures/*": ["__fixtures__/*"], "#src": ["src/index"], "#src/*": ["src/*"], "#tests/*": ["__tests__/*"]