@clerc/core 0.32.1 → 0.32.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.
Files changed (2) hide show
  1. package/dist/index.d.ts +62 -9
  2. package/package.json +3 -3
package/dist/index.d.ts CHANGED
@@ -19,6 +19,65 @@ declare global {
19
19
  }
20
20
  }
21
21
 
22
+ /**
23
+ Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
24
+
25
+ @example
26
+ ```
27
+ import type {Simplify} from 'type-fest';
28
+
29
+ type PositionProps = {
30
+ top: number;
31
+ left: number;
32
+ };
33
+
34
+ type SizeProps = {
35
+ width: number;
36
+ height: number;
37
+ };
38
+
39
+ // In your editor, hovering over `Props` will show a flattened object with all the properties.
40
+ type Props = Simplify<PositionProps & SizeProps>;
41
+ ```
42
+
43
+ Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
44
+
45
+ If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
46
+
47
+ @example
48
+ ```
49
+ import type {Simplify} from 'type-fest';
50
+
51
+ interface SomeInterface {
52
+ foo: number;
53
+ bar?: string;
54
+ baz: number | undefined;
55
+ }
56
+
57
+ type SomeType = {
58
+ foo: number;
59
+ bar?: string;
60
+ baz: number | undefined;
61
+ };
62
+
63
+ const literal = {foo: 123, bar: 'hello', baz: 456};
64
+ const someType: SomeType = literal;
65
+ const someInterface: SomeInterface = literal;
66
+
67
+ function fn(object: Record<string, unknown>): void {}
68
+
69
+ fn(literal); // Good: literal object type is sealed
70
+ fn(someType); // Good: type is sealed
71
+ fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
72
+ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
73
+ ```
74
+
75
+ @link https://github.com/microsoft/TypeScript/issues/15300
76
+
77
+ @category Object
78
+ */
79
+ type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
80
+
22
81
  /**
23
82
  Omit any index signatures from the given object type, leaving only explicitly defined properties.
24
83
 
@@ -307,16 +366,10 @@ interface HandlerContext<C extends Commands = Commands, N extends keyof C = keyo
307
366
  resolved: boolean;
308
367
  hasRootOrAlias: boolean;
309
368
  hasRoot: boolean;
310
- raw: {
311
- [K in keyof ParseRaw<C[N]>]: ParseRaw<C[N]>[K];
312
- };
313
- parameters: {
314
- [K in keyof ParseParameters<C, N>]: ParseParameters<C, N>[K];
315
- };
369
+ raw: Simplify<ParseRaw<C[N]>>;
370
+ parameters: Simplify<ParseParameters<C, N>>;
316
371
  unknownFlags: ParsedFlags["unknownFlags"];
317
- flags: {
318
- [K in keyof ParseFlag<C, N>]: ParseFlag<C, N>[K];
319
- };
372
+ flags: Simplify<ParseFlag<C, N>>;
320
373
  cli: Clerc<C>;
321
374
  }
322
375
  type Handler<C extends Commands = Commands, K extends keyof C = keyof C> = (ctx: HandlerContext<C, K>) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/core",
3
- "version": "0.32.1",
3
+ "version": "0.32.3",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "description": "Clerc core",
6
6
  "keywords": [
@@ -50,9 +50,9 @@
50
50
  "defu": "^6.1.2",
51
51
  "is-platform": "^1.0.0",
52
52
  "lite-emit": "^1.4.0",
53
- "type-fest": "^3.5.3",
53
+ "type-fest": "^3.6.0",
54
54
  "type-flag": "^3.0.0",
55
- "@clerc/utils": "0.32.1"
55
+ "@clerc/utils": "0.32.3"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "puild --minify",