strict-ts-lib-v6.0 0.6.1 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,61 @@
1
1
  # strict-ts-lib-v6.0
2
2
 
3
+ ## 0.6.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 90bf42e: Two fixes to declarations that compiled fine and went wrong at the use site.
8
+
9
+ **`ReturnType<typeof setTimeout>` no longer comes out `unknown`.** `ReturnType`
10
+ and `InstanceType` spelled their conditional's `extends` clause
11
+ `(...args: readonly never[]) => infer R`. An overload set whose last member is
12
+ generic, with a rest parameter computed from its own type parameter, does not
13
+ match that — so the conditional took its false branch and produced `unknown`,
14
+ silently, because a false branch is a type rather than an error. `@types/node`'s
15
+ `setTimeout<TArgs extends any[]>(cb, ms?, ...args: MakeVoidParameterOptional<TArgs>)`
16
+ is exactly that shape once it merges with the DOM's `setTimeout`, so
17
+ `ReturnType<typeof setTimeout>` was `unknown` and could not be handed back to
18
+ `clearTimeout`.
19
+
20
+ The spelling is now a bare `never`, which is what the stock library itself uses
21
+ for `ThisParameterType` and `OmitThisParameter`, and which gives up none of the
22
+ `any` removal this library exists for. The type-parameter constraint is spelled
23
+ the same way, so the false branch is unreachable for any `T` the constraint
24
+ admits: "did not resolve" can no longer arrive as an `unknown` that propagates.
25
+
26
+ That `never` now has a name, `StrictLibInternals.AnyArguments`, declared in
27
+ `lib.es5.d.ts`. `any` reads two ways in a function type and only one of them is
28
+ what this library removes: `any` as a _value_ becomes `unknown` or `never` by
29
+ variance, while `any` as a _wildcard_ — the `(...args: any)` in `ReturnType` —
30
+ describes nothing at all and is there only to switch the parameter comparison
31
+ off. The stock library spells that wildcard two ways (`any` in `ReturnType`,
32
+ `never` in `ThisParameterType`); this library spells it one way, and the name
33
+ says which of the two readings is meant. Every such position uses it: the four
34
+ utility types and `ThisParameterType` in `lib.es5.d.ts`, the decorator context
35
+ type parameters in `lib.decorators.d.ts`, and `Reflect.construct`'s `newTarget`
36
+ in `lib.es2015.reflect.d.ts`. The last two were not broken; one spelling is so
37
+ that the trap cannot be re-dug, and so that grepping the name finds all of
38
+ them.
39
+
40
+ **A replacement callback's trailing arguments are `string | undefined`, not
41
+ `unknown`.** `String.prototype.replace` / `replaceAll` and the
42
+ `[Symbol.replace]` they dispatch to typed the captured groups `readonly
43
+ unknown[]`, which forced every caller to narrow with `isString` before using a
44
+ group that the pattern shows can never be absent. They are now
45
+ `readonly (string | undefined)[]` — the type of a capture group — so contextual
46
+ typing gives `string | undefined` and a `?? ''` or a `!== undefined` check is
47
+ enough. Reading the participating-group count off a regular expression literal
48
+ is not something the type system can do, so this trades a little soundness for
49
+ it: a callback may declare a parameter past the last capture as
50
+ `string | undefined` and be handed the offset instead. That is still narrower
51
+ than the `any[]` the stock library ships.
52
+
53
+ ## 0.6.2
54
+
55
+ ### Patch Changes
56
+
57
+ - 68452d4: Allow `0` as `toExponential`'s `fractionDigits`: the parameter type becomes `UintRangeInclusive<0, 100>`. ECMA-262 accepts 0–100 — `(1).toExponential(0)` is legal and returns `'1e+0'` — so the previous lower bound of 1 rejected a valid call.
58
+
3
59
  ## 0.6.1
4
60
 
5
61
  ### Patch Changes
@@ -1,3 +1,5 @@
1
+ /// <reference lib="es5" />
2
+
1
3
  /**
2
4
  * The decorator context types provided to class element decorators.
3
5
  */
@@ -26,8 +28,11 @@ type DecoratorMetadata = typeof globalThis extends {
26
28
  * @template Class The type of the decorated class associated with this context.
27
29
  */
28
30
  interface ClassDecoratorContext<
29
- Class extends abstract new (...args: readonly never[]) => unknown =
30
- abstract new (...args: readonly never[]) => unknown,
31
+ Class extends abstract new (
32
+ ...args: StrictLibInternals.AnyArguments
33
+ ) => unknown = abstract new (
34
+ ...args: StrictLibInternals.AnyArguments
35
+ ) => unknown,
31
36
  > {
32
37
  /** The kind of element that was decorated. */
33
38
  readonly kind: 'class';
@@ -65,9 +70,12 @@ interface ClassDecoratorContext<
65
70
  */
66
71
  interface ClassMethodDecoratorContext<
67
72
  This = unknown,
68
- Value extends (this: This, ...args: readonly never[]) => unknown = (
73
+ Value extends (
74
+ this: This,
75
+ ...args: StrictLibInternals.AnyArguments
76
+ ) => unknown = (
69
77
  this: This,
70
- ...args: readonly never[]
78
+ ...args: StrictLibInternals.AnyArguments
71
79
  ) => unknown,
72
80
  > {
73
81
  /** The kind of class element that was decorated. */
@@ -1,3 +1,5 @@
1
+ /// <reference lib="es5" />
2
+
1
3
  declare namespace Reflect {
2
4
  /**
3
5
  * Calls the function with the specified object as the this value
@@ -27,7 +29,7 @@ declare namespace Reflect {
27
29
  function construct<A extends readonly unknown[], R>(
28
30
  target: new (...args: A) => R,
29
31
  argumentsList: Readonly<A>,
30
- newTarget?: new (...args: readonly never[]) => unknown,
32
+ newTarget?: new (...args: StrictLibInternals.AnyArguments) => unknown,
31
33
  ): R;
32
34
  function construct(
33
35
  target: Function,
@@ -187,7 +187,10 @@ interface RegExp {
187
187
  */
188
188
  [Symbol.replace](
189
189
  string: string,
190
- replacer: (substring: string, ...args: readonly unknown[]) => string,
190
+ replacer: (
191
+ substring: string,
192
+ ...args: readonly (string | undefined)[]
193
+ ) => string,
191
194
  ): string;
192
195
 
193
196
  /**
@@ -248,10 +251,16 @@ interface String {
248
251
  searchValue: {
249
252
  [Symbol.replace](
250
253
  string: string,
251
- replacer: (substring: string, ...args: readonly unknown[]) => string,
254
+ replacer: (
255
+ substring: string,
256
+ ...args: readonly (string | undefined)[]
257
+ ) => string,
252
258
  ): string;
253
259
  },
254
- replacer: (substring: string, ...args: readonly unknown[]) => string,
260
+ replacer: (
261
+ substring: string,
262
+ ...args: readonly (string | undefined)[]
263
+ ) => string,
255
264
  ): string;
256
265
 
257
266
  /**
@@ -13,6 +13,9 @@ interface String {
13
13
  */
14
14
  replaceAll(
15
15
  searchValue: string | RegExp,
16
- replacer: (substring: string, ...args: readonly unknown[]) => string,
16
+ replacer: (
17
+ substring: string,
18
+ ...args: readonly (string | undefined)[]
19
+ ) => string,
17
20
  ): string;
18
21
  }
@@ -350,7 +350,10 @@ declare const Function: FunctionConstructor;
350
350
  /**
351
351
  * Extracts the type of the 'this' parameter of a function type, or 'unknown' if the function type has no 'this' parameter.
352
352
  */
353
- type ThisParameterType<T> = T extends (this: infer U, ...args: never) => unknown
353
+ type ThisParameterType<T> = T extends (
354
+ this: infer U,
355
+ ...args: StrictLibInternals.AnyArguments
356
+ ) => unknown
354
357
  ? U
355
358
  : unknown;
356
359
 
@@ -531,7 +534,10 @@ interface String {
531
534
  */
532
535
  replace(
533
536
  searchValue: string | RegExp,
534
- replacer: (substring: string, ...args: readonly unknown[]) => string,
537
+ replacer: (
538
+ substring: string,
539
+ ...args: readonly (string | undefined)[]
540
+ ) => string,
535
541
  ): string;
536
542
 
537
543
  /**
@@ -645,7 +651,7 @@ interface Number {
645
651
  * @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.
646
652
  */
647
653
  toExponential(
648
- fractionDigits?: import('ts-type-forge').UintRangeInclusive<1, 100>,
654
+ fractionDigits?: import('ts-type-forge').UintRangeInclusive<0, 100>,
649
655
  ): string;
650
656
 
651
657
  /**
@@ -1897,25 +1903,23 @@ type NonNullable<T> = T & {};
1897
1903
  /**
1898
1904
  * Obtain the parameters of a function type in a tuple
1899
1905
  */
1900
- type Parameters<T extends (...args: readonly never[]) => unknown> = T extends (
1901
- ...args: infer P
1902
- ) => unknown
1903
- ? P
1904
- : never;
1906
+ type Parameters<
1907
+ T extends (...args: StrictLibInternals.AnyArguments) => unknown,
1908
+ > = T extends (...args: infer P) => unknown ? P : never;
1905
1909
 
1906
1910
  /**
1907
1911
  * Obtain the parameters of a constructor function type in a tuple
1908
1912
  */
1909
1913
  type ConstructorParameters<
1910
- T extends abstract new (...args: readonly never[]) => unknown,
1914
+ T extends abstract new (...args: StrictLibInternals.AnyArguments) => unknown,
1911
1915
  > = T extends abstract new (...args: infer P) => unknown ? P : never;
1912
1916
 
1913
1917
  /**
1914
1918
  * Obtain the return type of a function type
1915
1919
  */
1916
- type ReturnType<T extends (...args: readonly never[]) => unknown> = T extends (
1917
- ...args: readonly never[]
1918
- ) => infer R
1920
+ type ReturnType<
1921
+ T extends (...args: StrictLibInternals.AnyArguments) => unknown,
1922
+ > = T extends (...args: StrictLibInternals.AnyArguments) => infer R
1919
1923
  ? R
1920
1924
  : unknown;
1921
1925
 
@@ -1923,8 +1927,10 @@ type ReturnType<T extends (...args: readonly never[]) => unknown> = T extends (
1923
1927
  * Obtain the return type of a constructor function type
1924
1928
  */
1925
1929
  type InstanceType<
1926
- T extends abstract new (...args: readonly never[]) => unknown,
1927
- > = T extends abstract new (...args: readonly never[]) => infer R ? R : unknown;
1930
+ T extends abstract new (...args: StrictLibInternals.AnyArguments) => unknown,
1931
+ > = T extends abstract new (...args: StrictLibInternals.AnyArguments) => infer R
1932
+ ? R
1933
+ : unknown;
1928
1934
 
1929
1935
  /**
1930
1936
  * Convert string literal type to uppercase
@@ -5850,6 +5856,36 @@ interface Date {
5850
5856
  ): string;
5851
5857
  }
5852
5858
 
5859
+ declare namespace StrictLibInternals {
5860
+ /**
5861
+ * The rest-parameter type that means "matches any argument list". A
5862
+ * marker rather than a type anything has: it is `never`.
5863
+ *
5864
+ * `any` reads two ways in a function type, and only one of them is what
5865
+ * this library removes. `any` as a *value* — a return type, a property,
5866
+ * an argument a caller supplies — is the unsound one, and becomes
5867
+ * `unknown` or `never` here according to variance. `any` as a *wildcard*
5868
+ * — the `(...args: any)` in `ReturnType` — describes nothing at all: it
5869
+ * is there to switch the parameter comparison off, so that the
5870
+ * conditional matches whatever signature it is handed. The stock library
5871
+ * spells that marker two ways, `(...args: any)` in `ReturnType` and
5872
+ * `(...args: never)` in `ThisParameterType`. This library spells it one
5873
+ * way, and without `any`.
5874
+ *
5875
+ * Keep it a bare `never`. `never[]` and `readonly never[]` are ordinary
5876
+ * array types, checked like any array: neither is assignable to a tuple
5877
+ * with a required element, which is what the parameter list of the
5878
+ * signature being matched turns into once that signature's own rest
5879
+ * parameter stops being an array — as `@types/node`'s generic
5880
+ * `setTimeout` overload does. That is what made
5881
+ * `ReturnType<typeof setTimeout>` resolve to `unknown`, silently, a
5882
+ * conditional's false branch being a type rather than an error.
5883
+ *
5884
+ * @internal
5885
+ */
5886
+ type AnyArguments = never;
5887
+ }
5888
+
5853
5889
  type RawDateMutType = Date;
5854
5890
 
5855
5891
  type RawDateType = Readonly<RawDateMutType>;
@@ -1,3 +1,5 @@
1
+ /// <reference lib="es5" />
2
+
1
3
  /**
2
4
  * The decorator context types provided to class element decorators.
3
5
  */
@@ -26,8 +28,11 @@ type DecoratorMetadata = typeof globalThis extends {
26
28
  * @template Class The type of the decorated class associated with this context.
27
29
  */
28
30
  interface ClassDecoratorContext<
29
- Class extends abstract new (...args: readonly never[]) => unknown =
30
- abstract new (...args: readonly never[]) => unknown,
31
+ Class extends abstract new (
32
+ ...args: StrictLibInternals.AnyArguments
33
+ ) => unknown = abstract new (
34
+ ...args: StrictLibInternals.AnyArguments
35
+ ) => unknown,
31
36
  > {
32
37
  /** The kind of element that was decorated. */
33
38
  readonly kind: 'class';
@@ -65,9 +70,12 @@ interface ClassDecoratorContext<
65
70
  */
66
71
  interface ClassMethodDecoratorContext<
67
72
  This = unknown,
68
- Value extends (this: This, ...args: readonly never[]) => unknown = (
73
+ Value extends (
74
+ this: This,
75
+ ...args: StrictLibInternals.AnyArguments
76
+ ) => unknown = (
69
77
  this: This,
70
- ...args: readonly never[]
78
+ ...args: StrictLibInternals.AnyArguments
71
79
  ) => unknown,
72
80
  > {
73
81
  /** The kind of class element that was decorated. */
@@ -1,3 +1,5 @@
1
+ /// <reference lib="es5" />
2
+
1
3
  declare namespace Reflect {
2
4
  /**
3
5
  * Calls the function with the specified object as the this value
@@ -27,7 +29,7 @@ declare namespace Reflect {
27
29
  function construct<A extends readonly unknown[], R>(
28
30
  target: new (...args: A) => R,
29
31
  argumentsList: Readonly<A>,
30
- newTarget?: new (...args: readonly never[]) => unknown,
32
+ newTarget?: new (...args: StrictLibInternals.AnyArguments) => unknown,
31
33
  ): R;
32
34
  function construct(
33
35
  target: Function,
@@ -187,7 +187,10 @@ interface RegExp {
187
187
  */
188
188
  [Symbol.replace](
189
189
  string: string,
190
- replacer: (substring: string, ...args: readonly unknown[]) => string,
190
+ replacer: (
191
+ substring: string,
192
+ ...args: readonly (string | undefined)[]
193
+ ) => string,
191
194
  ): string;
192
195
 
193
196
  /**
@@ -251,10 +254,16 @@ interface String {
251
254
  searchValue: {
252
255
  [Symbol.replace](
253
256
  string: string,
254
- replacer: (substring: string, ...args: readonly unknown[]) => string,
257
+ replacer: (
258
+ substring: string,
259
+ ...args: readonly (string | undefined)[]
260
+ ) => string,
255
261
  ): string;
256
262
  },
257
- replacer: (substring: string, ...args: readonly unknown[]) => string,
263
+ replacer: (
264
+ substring: string,
265
+ ...args: readonly (string | undefined)[]
266
+ ) => string,
258
267
  ): string;
259
268
 
260
269
  /**
@@ -13,6 +13,9 @@ interface String {
13
13
  */
14
14
  replaceAll(
15
15
  searchValue: string | RegExp,
16
- replacer: (substring: string, ...args: readonly unknown[]) => string,
16
+ replacer: (
17
+ substring: string,
18
+ ...args: readonly (string | undefined)[]
19
+ ) => string,
17
20
  ): string;
18
21
  }
@@ -352,7 +352,10 @@ declare const Function: FunctionConstructor;
352
352
  /**
353
353
  * Extracts the type of the 'this' parameter of a function type, or 'unknown' if the function type has no 'this' parameter.
354
354
  */
355
- type ThisParameterType<T> = T extends (this: infer U, ...args: never) => unknown
355
+ type ThisParameterType<T> = T extends (
356
+ this: infer U,
357
+ ...args: StrictLibInternals.AnyArguments
358
+ ) => unknown
356
359
  ? U
357
360
  : unknown;
358
361
 
@@ -539,7 +542,10 @@ interface String {
539
542
  */
540
543
  replace(
541
544
  searchValue: string | RegExp,
542
- replacer: (substring: string, ...args: readonly unknown[]) => string,
545
+ replacer: (
546
+ substring: string,
547
+ ...args: readonly (string | undefined)[]
548
+ ) => string,
543
549
  ): string;
544
550
 
545
551
  /**
@@ -665,7 +671,7 @@ interface Number {
665
671
  * @param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.
666
672
  */
667
673
  toExponential(
668
- fractionDigits?: import('ts-type-forge').UintRangeInclusive<1, 100>,
674
+ fractionDigits?: import('ts-type-forge').UintRangeInclusive<0, 100>,
669
675
  ): string;
670
676
 
671
677
  /**
@@ -2052,25 +2058,23 @@ type NonNullable<T> = T & {};
2052
2058
  /**
2053
2059
  * Obtain the parameters of a function type in a tuple
2054
2060
  */
2055
- type Parameters<T extends (...args: readonly never[]) => unknown> = T extends (
2056
- ...args: infer P
2057
- ) => unknown
2058
- ? P
2059
- : never;
2061
+ type Parameters<
2062
+ T extends (...args: StrictLibInternals.AnyArguments) => unknown,
2063
+ > = T extends (...args: infer P) => unknown ? P : never;
2060
2064
 
2061
2065
  /**
2062
2066
  * Obtain the parameters of a constructor function type in a tuple
2063
2067
  */
2064
2068
  type ConstructorParameters<
2065
- T extends abstract new (...args: readonly never[]) => unknown,
2069
+ T extends abstract new (...args: StrictLibInternals.AnyArguments) => unknown,
2066
2070
  > = T extends abstract new (...args: infer P) => unknown ? P : never;
2067
2071
 
2068
2072
  /**
2069
2073
  * Obtain the return type of a function type
2070
2074
  */
2071
- type ReturnType<T extends (...args: readonly never[]) => unknown> = T extends (
2072
- ...args: readonly never[]
2073
- ) => infer R
2075
+ type ReturnType<
2076
+ T extends (...args: StrictLibInternals.AnyArguments) => unknown,
2077
+ > = T extends (...args: StrictLibInternals.AnyArguments) => infer R
2074
2078
  ? R
2075
2079
  : unknown;
2076
2080
 
@@ -2078,8 +2082,10 @@ type ReturnType<T extends (...args: readonly never[]) => unknown> = T extends (
2078
2082
  * Obtain the return type of a constructor function type
2079
2083
  */
2080
2084
  type InstanceType<
2081
- T extends abstract new (...args: readonly never[]) => unknown,
2082
- > = T extends abstract new (...args: readonly never[]) => infer R ? R : unknown;
2085
+ T extends abstract new (...args: StrictLibInternals.AnyArguments) => unknown,
2086
+ > = T extends abstract new (...args: StrictLibInternals.AnyArguments) => infer R
2087
+ ? R
2088
+ : unknown;
2083
2089
 
2084
2090
  /**
2085
2091
  * Convert string literal type to uppercase
@@ -6511,6 +6517,36 @@ interface Date {
6511
6517
  ): string;
6512
6518
  }
6513
6519
 
6520
+ declare namespace StrictLibInternals {
6521
+ /**
6522
+ * The rest-parameter type that means "matches any argument list". A
6523
+ * marker rather than a type anything has: it is `never`.
6524
+ *
6525
+ * `any` reads two ways in a function type, and only one of them is what
6526
+ * this library removes. `any` as a *value* — a return type, a property,
6527
+ * an argument a caller supplies — is the unsound one, and becomes
6528
+ * `unknown` or `never` here according to variance. `any` as a *wildcard*
6529
+ * — the `(...args: any)` in `ReturnType` — describes nothing at all: it
6530
+ * is there to switch the parameter comparison off, so that the
6531
+ * conditional matches whatever signature it is handed. The stock library
6532
+ * spells that marker two ways, `(...args: any)` in `ReturnType` and
6533
+ * `(...args: never)` in `ThisParameterType`. This library spells it one
6534
+ * way, and without `any`.
6535
+ *
6536
+ * Keep it a bare `never`. `never[]` and `readonly never[]` are ordinary
6537
+ * array types, checked like any array: neither is assignable to a tuple
6538
+ * with a required element, which is what the parameter list of the
6539
+ * signature being matched turns into once that signature's own rest
6540
+ * parameter stops being an array — as `@types/node`'s generic
6541
+ * `setTimeout` overload does. That is what made
6542
+ * `ReturnType<typeof setTimeout>` resolve to `unknown`, silently, a
6543
+ * conditional's false branch being a type rather than an error.
6544
+ *
6545
+ * @internal
6546
+ */
6547
+ type AnyArguments = never;
6548
+ }
6549
+
6514
6550
  type RawDateMutType = Date;
6515
6551
 
6516
6552
  type RawDateType = Readonly<RawDateMutType>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strict-ts-lib-v6.0",
3
- "version": "0.6.1",
3
+ "version": "0.6.3",
4
4
  "private": false,
5
5
  "description": "Strict TypeScript 6.0.3 standard library (all libs in one package)",
6
6
  "license": "Apache-2.0",