Skip to content

Commit d686e97

Browse files
authored
feat: support TypeScript up to version 5.2 (#82)
* feat: support TypeScript up to version 5.2 BREAKING CHANGE: Support for TypeScript 5.0 and lower has been dropped.
1 parent 16033c8 commit d686e97

30 files changed

+1958
-1962
lines changed

.eslintrc.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ const config = {
77
project: ['./tsconfig.lib.json', './tsconfig.test.json'],
88
},
99
plugins: ['@typescript-eslint', 'import'],
10-
extends: [
11-
'eslint:recommended',
12-
'plugin:@typescript-eslint/recommended',
13-
'plugin:@typescript-eslint/recommended-requiring-type-checking',
14-
'prettier',
15-
],
10+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/strict-type-checked', 'prettier'],
1611
rules: {
1712
'no-fallthrough': 'off', // checked by TS compiler
1813
'object-shorthand': ['error', 'always'],
1914
'sort-imports': ['error', { ignoreDeclarationSort: true }],
2015
'@typescript-eslint/no-explicit-any': 'off',
2116
'@typescript-eslint/no-unused-vars': 'off',
17+
'@typescript-eslint/no-invalid-void-type': 'off',
18+
'@typescript-eslint/no-throw-literal': 'off',
2219
'import/extensions': ['error', 'ignorePackages'],
2320
},
2421
overrides: [

etc/types.api.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export abstract class BaseTypeImpl<ResultType, TypeConfig = unknown> implements
6464
protected createAutoCastAllType(): this;
6565
protected createResult(input: unknown, result: unknown, validatorResult: ValidationResult): Result<ResultType>;
6666
readonly enumerableLiteralDomain?: Iterable<LiteralValue>;
67-
extendWith<E>(factory: (type: this) => E): this & E;
67+
extendWith<const E>(factory: (type: this) => E): this & E;
6868
get is(): TypeguardFor<ResultType>;
6969
literal(input: DeepUnbranded<ResultType>): ResultType;
7070
maybeStringify(value: ResultType): string | undefined;
@@ -75,9 +75,9 @@ export abstract class BaseTypeImpl<ResultType, TypeConfig = unknown> implements
7575
protected typeParser?(input: unknown, options: ValidationOptions): Result<unknown>;
7676
protected abstract typeValidator(input: unknown, options: ValidationOptions): Result<ResultType>;
7777
validate(input: unknown, options?: ValidationOptions): Result<ResultType>;
78-
withBrand<BrandName extends string>(name: BrandName): Type<Branded<ResultType, BrandName>, TypeConfig>;
79-
withConfig<BrandName extends string>(name: BrandName, newConfig: TypeConfig): Type<Branded<ResultType, BrandName>, TypeConfig>;
80-
withConstraint<BrandName extends string>(name: BrandName, constraint: Validator<ResultType>): Type<Branded<ResultType, BrandName>, TypeConfig>;
78+
withBrand<const BrandName extends string>(name: BrandName): Type<Branded<ResultType, BrandName>, TypeConfig>;
79+
withConfig<const BrandName extends string>(name: BrandName, newConfig: TypeConfig): Type<Branded<ResultType, BrandName>, TypeConfig>;
80+
withConstraint<const BrandName extends string>(name: BrandName, constraint: Validator<ResultType>): Type<Branded<ResultType, BrandName>, TypeConfig>;
8181
withName(name: string): this;
8282
withParser(...args: [newConstructor: (i: unknown) => unknown] | [name: string, newConstructor: (i: unknown) => unknown] | [options: ParserOptions, newConstructor: (i: unknown) => unknown]): this;
8383
withValidation(validation: Validator<ResultType>): this;
@@ -230,7 +230,7 @@ export interface LengthChecksConfig {
230230
export type LengthViolation = 'minLength' | 'maxLength';
231231

232232
// @public (undocumented)
233-
export function literal<T extends LiteralValue>(value: T): TypeImpl<LiteralType<T>>;
233+
export function literal<const T extends LiteralValue>(value: T): TypeImpl<LiteralType<T>>;
234234

235235
// @public
236236
export class LiteralType<ResultType extends LiteralValue> extends BaseTypeImpl<ResultType> {
@@ -345,7 +345,7 @@ export function partial<Props extends Properties>(...args: [props: Props] | [nam
345345
export type PartialType<Props extends Properties> = TypeImpl<InterfaceType<Props, Partial<TypeOfProperties<Writable<Props>>>>>;
346346

347347
// @public (undocumented)
348-
export function pattern<BrandName extends string>(name: BrandName, regExp: RegExp, customMessage?: StringTypeConfig['customMessage']): Type<Branded<string, BrandName>, StringTypeConfig>;
348+
export function pattern<const BrandName extends string>(name: BrandName, regExp: RegExp, customMessage?: StringTypeConfig['customMessage']): Type<Branded<string, BrandName>, StringTypeConfig>;
349349

350350
// @public
351351
export type PossibleDiscriminator = {
@@ -370,7 +370,7 @@ export function printPath(path: ReadonlyArray<PropertyKey>): string;
370370
export function printValue(input: unknown, budget?: number, visited?: Set<unknown>): string;
371371

372372
// @public
373-
export type Properties = Record<string, Type<unknown>>;
373+
export type Properties = Record<string, Type<any>>;
374374

375375
// @public
376376
export type PropertiesInfo<Props extends Properties = Properties> = {
@@ -494,7 +494,7 @@ Extract<Input, ResultType>
494494
// @public
495495
export type TypeImpl<Impl extends BaseTypeImpl<any, any>> = Impl & {
496496
new (input: unknown): TypeOf<Impl>;
497-
(input: unknown): TypeOf<Impl>;
497+
(this: void, input: unknown): TypeOf<Impl>;
498498
};
499499

500500
// @public
@@ -640,7 +640,7 @@ export const voidType: TypeImpl<LiteralType<void>>;
640640

641641
// @public (undocumented)
642642
export type WithBrands<T, BrandNames extends string> = T & {
643-
[brands]: {
643+
readonly [brands]: {
644644
[P in BrandNames]: true;
645645
};
646646
};

jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const config = {
1313
coverageThreshold: {
1414
global: {
1515
statements: -3,
16-
branches: -16,
16+
branches: -15,
1717
functions: -1,
1818
lines: 100,
1919
},

markdown/types.basetypeimpl.extendwith.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Extend the Type with additional static methods and properties.
99
**Signature:**
1010

1111
```typescript
12-
extendWith<E>(factory: (type: this) => E): this & E;
12+
extendWith<const E>(factory: (type: this) => E): this & E;
1313
```
1414
1515
## Parameters

markdown/types.basetypeimpl.withbrand.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Create a new instance of this Type with the given name.
99
**Signature:**
1010

1111
```typescript
12-
withBrand<BrandName extends string>(name: BrandName): Type<Branded<ResultType, BrandName>, TypeConfig>;
12+
withBrand<const BrandName extends string>(name: BrandName): Type<Branded<ResultType, BrandName>, TypeConfig>;
1313
```
1414
1515
## Parameters

markdown/types.basetypeimpl.withconfig.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Create a new instance of this Type with the additional type-specific config, suc
99
**Signature:**
1010

1111
```typescript
12-
withConfig<BrandName extends string>(name: BrandName, newConfig: TypeConfig): Type<Branded<ResultType, BrandName>, TypeConfig>;
12+
withConfig<const BrandName extends string>(name: BrandName, newConfig: TypeConfig): Type<Branded<ResultType, BrandName>, TypeConfig>;
1313
```
1414
1515
## Parameters

markdown/types.basetypeimpl.withconstraint.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Create a new type use the given constraint function to restrict the current type
99
**Signature:**
1010

1111
```typescript
12-
withConstraint<BrandName extends string>(name: BrandName, constraint: Validator<ResultType>): Type<Branded<ResultType, BrandName>, TypeConfig>;
12+
withConstraint<const BrandName extends string>(name: BrandName, constraint: Validator<ResultType>): Type<Branded<ResultType, BrandName>, TypeConfig>;
1313
```
1414
1515
## Parameters

markdown/types.literal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
**Signature:**
88

99
```typescript
10-
export declare function literal<T extends LiteralValue>(value: T): TypeImpl<LiteralType<T>>;
10+
export declare function literal<const T extends LiteralValue>(value: T): TypeImpl<LiteralType<T>>;
1111
```
1212

1313
## Parameters

markdown/types.pattern.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
**Signature:**
88

99
```typescript
10-
export declare function pattern<BrandName extends string>(
10+
export declare function pattern<const BrandName extends string>(
1111
name: BrandName,
1212
regExp: RegExp,
1313
customMessage?: StringTypeConfig['customMessage'],

markdown/types.properties.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The properties of an object type.
99
**Signature:**
1010

1111
```typescript
12-
export type Properties = Record<string, Type<unknown>>;
12+
export type Properties = Record<string, Type<any>>;
1313
```
1414

1515
**References:** [Type](./types.type.md)

0 commit comments

Comments
 (0)