Skip to content

Commit

Permalink
Revision 0.34.14 (#1140)
Browse files Browse the repository at this point in the history
* Fix Compiler Promise Check

* ChangeLog

* Version
  • Loading branch information
sinclairzx81 authored Jan 16, 2025
1 parent cc6471a commit 870ab41
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
2 changes: 2 additions & 0 deletions changelog/0.34.0.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
### 0.34.0
- [Revision 0.34.14](https://github.com/sinclairzx81/typebox/pull/1140)
- [1139](https://github.com/sinclairzx81/typebox/issues/1139) Update TypeCompiler Check for Promise (use instanceof Promise over Thenable check)
- [Revision 0.34.13](https://github.com/sinclairzx81/typebox/pull/1124)
- Pre emptive fix for TypeScript 5.8.0-nightly to resolve symbol narrowing on Convert.
- [Revision 0.34.12](https://github.com/sinclairzx81/typebox/pull/1120)
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sinclair/typebox",
"version": "0.34.13",
"version": "0.34.14",
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
"keywords": [
"typescript",
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export namespace TypeCompiler {
}
}
function* FromPromise(schema: TPromise, references: TSchema[], value: string): IterableIterator<string> {
yield `(typeof value === 'object' && typeof ${value}.then === 'function')`
yield `${value} instanceof Promise`
}
function* FromRecord(schema: TRecord, references: TSchema[], value: string): IterableIterator<string> {
yield Policy.IsRecordLike(value)
Expand Down
16 changes: 8 additions & 8 deletions src/value/guard/guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ export type TypedArrayType =
// --------------------------------------------------------------------------
/** Returns true if this value is an async iterator */
export function IsAsyncIterator(value: unknown): value is AsyncIterableIterator<any> {
return IsObject(value) && Symbol.asyncIterator in value
return IsObject(value) && globalThis.Symbol.asyncIterator in value
}
/** Returns true if this value is an iterator */
export function IsIterator(value: unknown): value is IterableIterator<any> {
return IsObject(value) && Symbol.iterator in value
return IsObject(value) && globalThis.Symbol.iterator in value
}
// --------------------------------------------------------------------------
// Object Instances
// --------------------------------------------------------------------------
/** Returns true if this value is not an instance of a class */
export function IsStandardObject(value: unknown): value is ObjectType {
return IsObject(value) && (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)
return IsObject(value) && (globalThis.Object.getPrototypeOf(value) === Object.prototype || globalThis.Object.getPrototypeOf(value) === null)
}
/** Returns true if this value is an instance of a class */
export function IsInstanceObject(value: unknown): value is ObjectType {
Expand All @@ -72,11 +72,11 @@ export function IsInstanceObject(value: unknown): value is ObjectType {
// --------------------------------------------------------------------------
/** Returns true if this value is a Promise */
export function IsPromise(value: unknown): value is Promise<unknown> {
return value instanceof Promise
return value instanceof globalThis.Promise
}
/** Returns true if this value is a Date */
export function IsDate(value: unknown): value is Date {
return value instanceof Date && Number.isFinite(value.getTime())
return value instanceof Date && globalThis.Number.isFinite(value.getTime())
}
/** Returns true if this value is an instance of Map<K, T> */
export function IsMap(value: unknown): value is Map<unknown, unknown> {
Expand All @@ -92,7 +92,7 @@ export function IsRegExp(value: unknown): value is RegExp {
}
/** Returns true if this value is a typed array */
export function IsTypedArray(value: unknown): value is TypedArrayType {
return ArrayBuffer.isView(value)
return globalThis.ArrayBuffer.isView(value)
}
/** Returns true if the value is a Int8Array */
export function IsInt8Array(value: unknown): value is Int8Array {
Expand Down Expand Up @@ -154,7 +154,7 @@ export function IsObject(value: unknown): value is ObjectType {
}
/** Returns true if this value is an array, but not a typed array */
export function IsArray(value: unknown): value is ArrayType {
return Array.isArray(value) && !ArrayBuffer.isView(value)
return globalThis.Array.isArray(value) && !globalThis.ArrayBuffer.isView(value)
}
/** Returns true if this value is an undefined */
export function IsUndefined(value: unknown): value is undefined {
Expand All @@ -174,7 +174,7 @@ export function IsNumber(value: unknown): value is number {
}
/** Returns true if this value is an integer */
export function IsInteger(value: unknown): value is number {
return Number.isInteger(value)
return globalThis.Number.isInteger(value)
}
/** Returns true if this value is bigint */
export function IsBigInt(value: unknown): value is bigint {
Expand Down

0 comments on commit 870ab41

Please sign in to comment.