@deessejs/type-testing 0.2.0 → 0.3.1

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,33 @@
1
1
  # @deessejs/type-testing
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - feat: add type utility helpers
8
+
9
+ Add new type utilities for compile-time type testing:
10
+
11
+ ### Property Modifiers
12
+ - IsReadonly<T> - Check if all properties are readonly
13
+ - IsRequired<T> - Check if all properties are required
14
+ - IsPublic<T, K> - Check if property is public
15
+ - IsPrivate<T, K> - Check if property is private
16
+ - IsProtected<T, K> - Check if property is protected
17
+
18
+ ### Deep Type Manipulation
19
+ - DeepReadonly<T> - Make all properties readonly recursively
20
+ - DeepPartial<T> - Make all properties optional recursively
21
+ - RequiredKeys<T> - Get keys of required properties
22
+ - OptionalKeys<T> - Get keys of optional properties
23
+
24
+ ### Function Types
25
+ - IsConstructor<T> - Check if type is a constructor
26
+ - IsAbstract<T> - Check if type is abstract
27
+
28
+ ### Other
29
+ - IsNeverEqual<T, U> - Check if T and U are both never
30
+
3
31
  ## 0.2.0
4
32
 
5
33
  ### Minor Changes
package/README.md CHANGED
@@ -139,6 +139,27 @@ HasProperty<{ a: string }, 'b'> // false
139
139
  PropertyType<{ a: string }, 'a'> // string
140
140
  ```
141
141
 
142
+ ### Property Modifiers
143
+
144
+ ```typescript
145
+ import { IsReadonly, IsRequired, IsPublic, IsPrivate, IsProtected } from '@deessejs/type-testing'
146
+
147
+ // Check if all properties are readonly
148
+ IsReadonly<{ readonly a: string }> // true
149
+ IsReadonly<{ a: string }> // false
150
+
151
+ // Check if all properties are required
152
+ IsRequired<{ a: string }> // true
153
+ IsRequired<{ a?: string }> // false
154
+
155
+ // Check property visibility (uses naming convention)
156
+ IsPublic<{ a: string }, 'a'> // true
157
+ IsPrivate<{ __private: string }, '__private'> // true
158
+ IsProtected<{ _protected: string }, '_protected'> // true
159
+ ```
160
+
161
+ > **Note**: `IsPublic`, `IsPrivate`, and `IsProtected` use TypeScript's private field naming convention (`__` prefix) and common JavaScript convention (`_` prefix for protected). These are naming-convention-based checks, not actual TypeScript access modifiers (which don't exist for object properties).
162
+
142
163
  ### Function Types
143
164
 
144
165
  ```typescript
@@ -164,6 +185,51 @@ Length<['a', 'b', 'c']> // 3
164
185
  Length<[]> // 0
165
186
  ```
166
187
 
188
+ ### Deep Type Manipulation
189
+
190
+ ```typescript
191
+ import { DeepReadonly, DeepPartial, RequiredKeys, OptionalKeys } from '@deessejs/type-testing'
192
+
193
+ // Make all properties readonly recursively
194
+ DeepReadonly<{ a: string; b: { c: number } }>
195
+ // { readonly a: string; readonly b: { readonly c: number } }
196
+
197
+ // Make all properties optional recursively
198
+ DeepPartial<{ a: string; b: { c: number } }>
199
+ // { a?: string; b?: { c?: number } | undefined }
200
+
201
+ // Get keys of required properties
202
+ RequiredKeys<{ a: string; b?: number }> // 'a'
203
+
204
+ // Get keys of optional properties
205
+ OptionalKeys<{ a: string; b?: number }> // 'b'
206
+ ```
207
+
208
+ ### Constructor & Abstract Types
209
+
210
+ ```typescript
211
+ import { IsConstructor, IsAbstract } from '@deessejs/type-testing'
212
+
213
+ class Foo {}
214
+ abstract class Bar {}
215
+
216
+ IsConstructor<typeof Foo> // true
217
+ IsConstructor<Foo> // false (instance)
218
+ IsAbstract<typeof Bar> // true
219
+ IsAbstract<typeof Foo> // false
220
+ ```
221
+
222
+ ### Special Equality
223
+
224
+ ```typescript
225
+ import { IsNeverEqual } from '@deessejs/type-testing'
226
+
227
+ // Check if both types are never
228
+ // Differs from Equal<never, never> which returns false
229
+ IsNeverEqual<never, never> // true
230
+ IsNeverEqual<any, any> // false (any is not never)
231
+ ```
232
+
167
233
  ## Runtime Type Checking
168
234
 
169
235
  The library also provides runtime type checking utilities:
@@ -308,6 +374,7 @@ expectFalse<true>() // compile error
308
374
  | `Equal<T, U>` | Strict equality check |
309
375
  | `NotEqual<T, U>` | Inequality check |
310
376
  | `SimpleEqual<T, U>` | Simple equality for plain types |
377
+ | `IsNeverEqual<T, U>` | Check if both types are `never` |
311
378
  | `IsAny<T>` | Check if type is `any` |
312
379
  | `IsNever<T>` | Check if type is `never` |
313
380
  | `IsUnknown<T>` | Check if type is `unknown` |
@@ -323,9 +390,20 @@ expectFalse<true>() // compile error
323
390
  | `IsUninhabited<T>` | Check if type has no values |
324
391
  | `HasProperty<T, K>` | Check if type has property K |
325
392
  | `PropertyType<T, K>` | Get type of property K |
393
+ | `IsReadonly<T>` | Check if all properties are readonly |
394
+ | `IsRequired<T>` | Check if all properties are required |
395
+ | `IsPublic<T, K>` | Check if property is public |
396
+ | `IsPrivate<T, K>` | Check if property is private (naming convention) |
397
+ | `IsProtected<T, K>` | Check if property is protected (naming convention) |
398
+ | `DeepReadonly<T>` | Make all properties readonly recursively |
399
+ | `DeepPartial<T>` | Make all properties optional recursively |
400
+ | `RequiredKeys<T>` | Get keys of required properties |
401
+ | `OptionalKeys<T>` | Get keys of optional properties |
326
402
  | `Parameters<T>` | Get function parameters as tuple |
327
403
  | `ReturnType<T>` | Get function return type |
328
404
  | `Parameter<T, N>` | Get parameter at index N |
405
+ | `IsConstructor<T>` | Check if type is a constructor |
406
+ | `IsAbstract<T>` | Check if type is abstract |
329
407
  | `Length<T>` | Get tuple/array length |
330
408
  | `ExpectTrue<T>` | Assert T is true |
331
409
  | `ExpectEqual<T, U>` | Assert T equals U |
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Deep type manipulation utilities.
3
+ */
4
+ /**
5
+ * Makes all properties of a type readonly recursively.
6
+ * Properly handles arrays by making array elements readonly as well.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * type Test = DeepReadonly<{ a: string; b: { c: number } }>
11
+ * // { readonly a: string; readonly b: { readonly c: number } }
12
+ *
13
+ * type Test2 = DeepReadonly<{ items: { name: string }[] }>
14
+ * // { readonly items: readonly { readonly name: string }[] }
15
+ * ```
16
+ */
17
+ export type DeepReadonly<T> = T extends readonly (infer R)[] ? readonly DeepReadonly<R>[] : T extends (infer R)[] ? readonly DeepReadonly<R>[] : {
18
+ readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K];
19
+ };
20
+ /**
21
+ * Makes all properties of a type optional recursively.
22
+ * Properly handles arrays by making array elements optional as well.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * type Test = DeepPartial<{ a: string; b: { c: number } }>
27
+ * // { a?: string; b?: { c?: number } | undefined }
28
+ *
29
+ * type Test2 = DeepPartial<{ items: { name: string }[] }>
30
+ * // { items?: { name?: string | undefined }[] | undefined }
31
+ * ```
32
+ */
33
+ export type DeepPartial<T> = T extends readonly (infer R)[] ? DeepPartial<R>[] : T extends (infer R)[] ? DeepPartial<R>[] : {
34
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
35
+ };
36
+ /**
37
+ * Gets the keys of required properties from a type.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * type Test = RequiredKeys<{ a: string; b?: number }>
42
+ * // 'a'
43
+ * ```
44
+ */
45
+ export type RequiredKeys<T> = {
46
+ [K in keyof T]: {} extends Pick<T, K> ? never : K;
47
+ }[keyof T];
48
+ /**
49
+ * Gets the keys of optional properties from a type.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * type Test = OptionalKeys<{ a: string; b?: number }>
54
+ * // 'b'
55
+ * ```
56
+ */
57
+ export type OptionalKeys<T> = {
58
+ [K in keyof T]: {} extends Pick<T, K> ? K : never;
59
+ }[keyof T];
60
+ //# sourceMappingURL=deep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep.d.ts","sourceRoot":"","sources":["../../src/types/deep.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACxD,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,GAC1B,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACrB,SAAS,YAAY,CAAC,CAAC,CAAC,EAAE,GAC1B;IACE,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACzE,CAAA;AAEL;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACvD,WAAW,CAAC,CAAC,CAAC,EAAE,GAChB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACrB,WAAW,CAAC,CAAC,CAAC,EAAE,GAChB;KACG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChE,CAAA;AAEL;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;KAE3B,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC;CAClD,CAAC,MAAM,CAAC,CAAC,CAAA;AAEV;;;;;;;;GAQG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI;KAE3B,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,KAAK;CAClD,CAAC,MAAM,CAAC,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Deep type manipulation utilities.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=deep.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep.js","sourceRoot":"","sources":["../../src/types/deep.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Type equality utilities.
3
3
  */
4
+ import type { IsNever } from './special.js';
4
5
  /**
5
6
  * Checks if two types are strictly equal.
6
7
  * Uses a technique that compares the structure while handling
@@ -27,4 +28,21 @@ export type NotEqual<T, U> = Equal<T, U> extends true ? false : true;
27
28
  * Useful for simple type comparisons.
28
29
  */
29
30
  export type SimpleEqual<T, U> = [T, U] extends [U, T] ? true : false;
31
+ /**
32
+ * Checks if both T and U are `never`.
33
+ * This is a special case equality check that differs from Equal<T, U>
34
+ * because Equal<never, never> returns false in TypeScript.
35
+ *
36
+ * Note: `any` is not treated as `never` - this utility specifically
37
+ * checks for the `never` type. Use IsAny if you need to check for `any`.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * type Test = IsNeverEqual<never, never> // true
42
+ * type Test2 = IsNeverEqual<string, never> // false
43
+ * type Test3 = IsNeverEqual<never, string> // false
44
+ * type Test4 = IsNeverEqual<any, any> // false (any is not never)
45
+ * ```
46
+ */
47
+ export type IsNeverEqual<T, U> = IsNever<T> extends true ? IsNever<U> extends true ? true : false : false;
30
48
  //# sourceMappingURL=equality.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"equality.d.ts","sourceRoot":"","sources":["../../src/types/equality.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IACpB,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GACjE,IAAI,GACJ,KAAK,CAAA;AAEX;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,IAAI,CAAA;AAEpE;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA"}
1
+ {"version":3,"file":"equality.d.ts","sourceRoot":"","sources":["../../src/types/equality.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAE3C;;;;;;;;;;GAUG;AACH,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IACpB,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GACjE,IAAI,GACJ,KAAK,CAAA;AAEX;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,IAAI,GAAG,KAAK,GAAG,IAAI,CAAA;AAEpE;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;AAEpE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,GACpD,OAAO,CAAC,CAAC,CAAC,SAAS,IAAI,GACrB,IAAI,GACJ,KAAK,GACP,KAAK,CAAA"}
@@ -13,4 +13,26 @@ export type ReturnType<T extends (...args: any[]) => any> = T extends (...args:
13
13
  * Gets the parameter type at a specific index.
14
14
  */
15
15
  export type Parameter<T extends (...args: any[]) => any, N extends number> = Parameters<T>[N];
16
+ /**
17
+ * Checks if a type is a constructor.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * class Foo {}
22
+ * type Test = IsConstructor<typeof Foo> // true
23
+ * type Test2 = IsConstructor<Foo> // false
24
+ * ```
25
+ */
26
+ export type IsConstructor<T> = T extends new (...args: any[]) => any ? true : false;
27
+ /**
28
+ * Checks if a type is abstract.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * abstract class Foo {}
33
+ * type Test = IsAbstract<typeof Foo> // true
34
+ * type Test2 = IsAbstract<Foo> // false
35
+ * ```
36
+ */
37
+ export type IsAbstract<T> = T extends abstract new (...args: any[]) => any ? true : false;
16
38
  //# sourceMappingURL=function.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/types/function.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,CAAA;AAE3G;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAE7G;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,CAAC,SAAS,MAAM,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../src/types/function.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,GAAG,KAAK,CAAA;AAE3G;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAE7G;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,CAAC,SAAS,MAAM,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAE7F;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,IAAI,GAAG,KAAK,CAAA;AAEnF;;;;;;;;;GASG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GAAG,IAAI,GAAG,KAAK,CAAA"}
@@ -8,4 +8,5 @@ export * from './inhabitation.js';
8
8
  export * from './property.js';
9
9
  export * from './function.js';
10
10
  export * from './length.js';
11
+ export * from './deep.js';
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
@@ -9,4 +9,5 @@ export * from './inhabitation.js';
9
9
  export * from './property.js';
10
10
  export * from './function.js';
11
11
  export * from './length.js';
12
+ export * from './deep.js';
12
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,sBAAsB;AACtB,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,sBAAsB;AACtB,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA"}
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Property testing utilities.
3
3
  */
4
+ import type { Equal } from './equality';
4
5
  /**
5
6
  * Checks if a type has a specific property.
6
7
  */
@@ -9,4 +10,68 @@ export type HasProperty<T, K extends PropertyKey> = K extends keyof T ? true : f
9
10
  * Gets the type of a specific property from a type.
10
11
  */
11
12
  export type PropertyType<T, K extends keyof T> = T[K];
13
+ /**
14
+ * Checks if all properties of a type are readonly.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * type Test = IsReadonly<{ readonly a: string }> // true
19
+ * type Test2 = IsReadonly<{ a: string }> // false
20
+ * ```
21
+ */
22
+ export type IsReadonly<T> = Equal<{
23
+ [K in keyof T]: T[K];
24
+ }, {
25
+ readonly [K in keyof T]: T[K];
26
+ }> extends true ? true : false;
27
+ /**
28
+ * Checks if all properties of a type are required (not optional).
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * type Test = IsRequired<{ a: string }> // true
33
+ * type Test2 = IsRequired<{ a?: string }> // false
34
+ * ```
35
+ */
36
+ export type IsRequired<T> = Equal<{
37
+ [K in keyof T]-?: T[K];
38
+ }, {
39
+ [K in keyof T]: T[K];
40
+ }> extends true ? true : false;
41
+ /**
42
+ * Checks if a property is public (not private or protected).
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * type Test = IsPublic<{ a: string }, 'a'> // true
47
+ * ```
48
+ */
49
+ export type IsPublic<T, K extends PropertyKey> = K extends keyof T ? K extends `__${string}` ? false : true : false;
50
+ /**
51
+ * Checks if a property is private.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * type Test = IsPrivate<{ __private: string }, '__private'> // true
56
+ * type Test2 = IsPrivate<{ a: string }, 'a'> // false
57
+ * ```
58
+ */
59
+ export type IsPrivate<T, K extends PropertyKey> = K extends keyof T ? K extends `__${string}` ? true : false : false;
60
+ /**
61
+ * Checks if a property is protected.
62
+ * Uses the naming convention: properties starting with `_` (but not `__`)
63
+ * are considered protected.
64
+ *
65
+ * Note: TypeScript doesn't have actual `protected` access modifiers for
66
+ * object properties - this uses the common naming convention where
67
+ * protected properties are prefixed with `_`.
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * type Test = IsProtected<{ _protected: string }, '_protected'> // true
72
+ * type Test2 = IsProtected<{ a: string }, 'a'> // false
73
+ * type Test3 = IsProtected<{ __private: string }, '__private'> // false (private)
74
+ * ```
75
+ */
76
+ export type IsProtected<T, K extends PropertyKey> = K extends keyof T ? K extends `_${string}` ? K extends `__${string}` ? false : true : false : false;
12
77
  //# sourceMappingURL=property.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../src/types/property.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;AAEpF;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA"}
1
+ {"version":3,"file":"property.d.ts","sourceRoot":"","sources":["../../src/types/property.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEvC;;GAEG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAA;AAEpF;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;AAErD;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,KAAK,CAAC;KAC/B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACrB,EAAE;IACD,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAC9B,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAA;AAE9B;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,KAAK,CAAC;KAC/B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACvB,EAAE;KACA,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACrB,CAAC,SAAS,IAAI,GAAG,IAAI,GAAG,KAAK,CAAA;AAE9B;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS,MAAM,CAAC,GAC9D,CAAC,SAAS,KAAK,MAAM,EAAE,GACrB,KAAK,GACL,IAAI,GACN,KAAK,CAAA;AAET;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS,MAAM,CAAC,GAC/D,CAAC,SAAS,KAAK,MAAM,EAAE,GACrB,IAAI,GACJ,KAAK,GACP,KAAK,CAAA;AAET;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS,MAAM,CAAC,GACjE,CAAC,SAAS,IAAI,MAAM,EAAE,GACpB,CAAC,SAAS,KAAK,MAAM,EAAE,GACrB,KAAK,GACL,IAAI,GACN,KAAK,GACP,KAAK,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deessejs/type-testing",
3
- "version": "0.2.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
package/public/icon.png CHANGED
Binary file