@sinclair/typebox 0.31.20 → 0.31.21

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/package.json +1 -1
  2. package/typebox.js +41 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.31.20",
3
+ "version": "0.31.21",
4
4
  "description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/typebox.js CHANGED
@@ -224,6 +224,9 @@ var TypeGuard;
224
224
  function IsOptionalSchema(value) {
225
225
  return ValueGuard.IsUndefined(value) || TSchema(value);
226
226
  }
227
+ // ----------------------------------------------------------------
228
+ // Types
229
+ // ----------------------------------------------------------------
227
230
  /** Returns true if the given value is TAny */
228
231
  function TAny(schema) {
229
232
  // prettier-ignore
@@ -587,39 +590,39 @@ var TypeGuard;
587
590
  TypeGuard.TOptional = TOptional;
588
591
  /** Returns true if the given value is TSchema */
589
592
  function TSchema(schema) {
590
- return (ValueGuard.IsObject(schema) &&
591
- (TAny(schema) ||
592
- TArray(schema) ||
593
- TBoolean(schema) ||
594
- TBigInt(schema) ||
595
- TAsyncIterator(schema) ||
596
- TConstructor(schema) ||
597
- TDate(schema) ||
598
- TFunction(schema) ||
599
- TInteger(schema) ||
600
- TIntersect(schema) ||
601
- TIterator(schema) ||
602
- TLiteral(schema) ||
603
- TNever(schema) ||
604
- TNot(schema) ||
605
- TNull(schema) ||
606
- TNumber(schema) ||
607
- TObject(schema) ||
608
- TPromise(schema) ||
609
- TRecord(schema) ||
610
- TRef(schema) ||
611
- TString(schema) ||
612
- TSymbol(schema) ||
613
- TTemplateLiteral(schema) ||
614
- TThis(schema) ||
615
- TTuple(schema) ||
616
- TUndefined(schema) ||
617
- TUnion(schema) ||
618
- TUint8Array(schema) ||
619
- TUnknown(schema) ||
620
- TUnsafe(schema) ||
621
- TVoid(schema) ||
622
- (TKind(schema) && TypeRegistry.Has(schema[exports.Kind]))));
593
+ // prettier-ignore
594
+ return (ValueGuard.IsObject(schema)) && (TAny(schema) ||
595
+ TArray(schema) ||
596
+ TBoolean(schema) ||
597
+ TBigInt(schema) ||
598
+ TAsyncIterator(schema) ||
599
+ TConstructor(schema) ||
600
+ TDate(schema) ||
601
+ TFunction(schema) ||
602
+ TInteger(schema) ||
603
+ TIntersect(schema) ||
604
+ TIterator(schema) ||
605
+ TLiteral(schema) ||
606
+ TNever(schema) ||
607
+ TNot(schema) ||
608
+ TNull(schema) ||
609
+ TNumber(schema) ||
610
+ TObject(schema) ||
611
+ TPromise(schema) ||
612
+ TRecord(schema) ||
613
+ TRef(schema) ||
614
+ TString(schema) ||
615
+ TSymbol(schema) ||
616
+ TTemplateLiteral(schema) ||
617
+ TThis(schema) ||
618
+ TTuple(schema) ||
619
+ TUndefined(schema) ||
620
+ TUnion(schema) ||
621
+ TUint8Array(schema) ||
622
+ TUnknown(schema) ||
623
+ TUnsafe(schema) ||
624
+ TVoid(schema) ||
625
+ (TKind(schema) && TypeRegistry.Has(schema[exports.Kind])));
623
626
  }
624
627
  TypeGuard.TSchema = TSchema;
625
628
  })(TypeGuard || (exports.TypeGuard = TypeGuard = {}));
@@ -995,8 +998,12 @@ var TypeExtends;
995
998
  !TypeGuard.TObject(right) ? TypeExtendsResult.False :
996
999
  (() => {
997
1000
  for (const key of Object.getOwnPropertyNames(right.properties)) {
998
- if (!(key in left.properties))
1001
+ if (!(key in left.properties) && !TypeGuard.TOptional(right.properties[key])) {
999
1002
  return TypeExtendsResult.False;
1003
+ }
1004
+ if (TypeGuard.TOptional(right.properties[key])) {
1005
+ return TypeExtendsResult.True;
1006
+ }
1000
1007
  if (Property(left.properties[key], right.properties[key]) === TypeExtendsResult.False) {
1001
1008
  return TypeExtendsResult.False;
1002
1009
  }