@sinclair/typebox 0.26.0-dev.3 → 0.26.0-dev.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.26.0-dev.3",
3
+ "version": "0.26.0-dev.4",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/typebox.d.ts CHANGED
@@ -575,12 +575,20 @@ export declare class StandardTypeBuilder extends TypeBuilder {
575
575
  Omit<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: readonly [...K], options?: SchemaOptions): TOmit<T, K[number]>;
576
576
  /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
577
577
  Omit<T extends TSchema, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: SchemaOptions): TOmit<T, TUnionOfLiteral<K>>;
578
+ /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
579
+ Omit<T extends TSchema, K extends TLiteral<string>>(schema: T, key: K, options?: SchemaOptions): TOmit<T, K['const']>;
580
+ /** `[Standard]` Creates a mapped type whose keys are omitted from the given type */
581
+ Omit<T extends TSchema, K extends TNever>(schema: T, key: K, options?: SchemaOptions): TOmit<T, never>;
578
582
  /** `[Standard]` Creates a mapped type where all properties are Optional */
579
583
  Partial<T extends TSchema>(schema: T, options?: ObjectOptions): TPartial<T>;
580
584
  /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
581
585
  Pick<T extends TSchema, K extends (keyof Static<T>)[]>(schema: T, keys: readonly [...K], options?: SchemaOptions): TPick<T, K[number]>;
582
586
  /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
583
587
  Pick<T extends TSchema, K extends TUnion<TLiteral<string>[]>>(schema: T, keys: K, options?: SchemaOptions): TPick<T, TUnionOfLiteral<K>>;
588
+ /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
589
+ Pick<T extends TSchema, K extends TLiteral<string>>(schema: T, key: K, options?: SchemaOptions): TPick<T, K['const']>;
590
+ /** `[Standard]` Creates a mapped type whose keys are picked from the given type */
591
+ Pick<T extends TSchema, K extends TNever>(schema: T, key: K, options?: SchemaOptions): TPick<T, never>;
584
592
  /** `[Standard]` Creates an Object type from the given Literal Union */
585
593
  Record<K extends TUnion<TLiteral<string | number>[]>, T extends TSchema>(key: K, schema: T, options?: ObjectOptions): TObject<TRecordPropertiesFromUnionLiteral<K, T>>;
586
594
  /** `[Standard]` Creates an Object type from the given Literal Union */
package/typebox.js CHANGED
@@ -1638,7 +1638,11 @@ class StandardTypeBuilder extends TypeBuilder {
1638
1638
  }
1639
1639
  }
1640
1640
  Omit(schema, unresolved, options = {}) {
1641
- const keys = TypeGuard.TUnionLiteral(unresolved) ? unresolved.anyOf.map((schema) => schema.const) : unresolved;
1641
+ // prettier-ignore
1642
+ const keys = TypeGuard.TUnionLiteral(unresolved) ? unresolved.anyOf.map((schema) => schema.const) :
1643
+ TypeGuard.TLiteral(unresolved) ? [unresolved.const] :
1644
+ TypeGuard.TNever(unresolved) ? [] :
1645
+ unresolved;
1642
1646
  // prettier-ignore
1643
1647
  return ObjectMap.Map(TypeClone.Clone(ReferenceRegistry.Deref(schema), {}), (schema) => {
1644
1648
  if (schema.required) {
@@ -1680,7 +1684,11 @@ class StandardTypeBuilder extends TypeBuilder {
1680
1684
  }, options);
1681
1685
  }
1682
1686
  Pick(schema, unresolved, options = {}) {
1683
- const keys = TypeGuard.TUnionLiteral(unresolved) ? unresolved.anyOf.map((schema) => schema.const) : unresolved;
1687
+ // prettier-ignore
1688
+ const keys = TypeGuard.TUnionLiteral(unresolved) ? unresolved.anyOf.map((schema) => schema.const) :
1689
+ TypeGuard.TLiteral(unresolved) ? [unresolved.const] :
1690
+ TypeGuard.TNever(unresolved) ? [] :
1691
+ unresolved;
1684
1692
  // prettier-ignore
1685
1693
  return ObjectMap.Map(TypeClone.Clone(ReferenceRegistry.Deref(schema), {}), (schema) => {
1686
1694
  if (schema.required) {
@@ -1779,7 +1787,7 @@ class StandardTypeBuilder extends TypeBuilder {
1779
1787
  if (anyOf.length === 0)
1780
1788
  return this.Never(options);
1781
1789
  if (anyOf.length === 1)
1782
- return TypeClone.Clone(anyOf[0], options);
1790
+ return this.Create(TypeClone.Clone(anyOf[0], options));
1783
1791
  const clonedAnyOf = anyOf.map((schema) => TypeClone.Clone(schema, {}));
1784
1792
  return this.Create({ ...options, [exports.Kind]: 'Union', anyOf: clonedAnyOf });
1785
1793
  }