MCPcopy
hub / github.com/arktypeio/arktype / compareTsTypes

Function compareTsTypes

ark/attest/cache/writeAssertionCache.ts:310–332  ·  view source on GitHub ↗
(
	l: StringifiableType,
	r: StringifiableType
)

Source from the content-addressed store, hash-verified

308export type TypeRelationship = "subtype" | "supertype" | "equality" | "none"
309
310export const compareTsTypes = (
311 l: StringifiableType,
312 r: StringifiableType
313): TypeRelationship => {
314 const lString = l.toString()
315 const rString = r.toString()
316 // Ensure two unresolvable types are not treated as equivalent
317 if (l.isUnresolvable || r.isUnresolvable) return "none"
318 // Treat `any` as a supertype of every other type
319 if (lString === "any") return rString === "any" ? "equality" : "supertype"
320 if (rString === "any") return "subtype"
321 // Otherwise, determine if the types are equivalent by checking mutual assignability
322 const checker = getInternalTypeChecker()
323 const isSubtype = checker.isTypeAssignableTo(l, r)
324 const isSupertype = checker.isTypeAssignableTo(r, l)
325 return (
326 isSubtype ?
327 isSupertype ? "equality"
328 : "subtype"
329 : isSupertype ? "supertype"
330 : "none"
331 )
332}
333
334export const checkDiagnosticMessages = (
335 attestCall: ts.CallExpression,

Callers 1

serializeArgFunction · 0.85

Calls 2

getInternalTypeCheckerFunction · 0.90
toStringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…