Skip to content

Commit

Permalink
Fix Compiler Promise Check
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Jan 16, 2025
1 parent bcfee3d commit 8e8f596
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
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 8e8f596

Please sign in to comment.