MCPcopy Create free account
hub / github.com/arktypeio/arktype / compareTsTypes

Function compareTsTypes

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

Source from the content-addressed store, hash-verified

272 .join("\n")
273
274export const compareTsTypes = (
275 l: StringifiableType,
276 r: StringifiableType
277): TypeRelationship => {
278 const lString = l.toString()
279 const rString = r.toString()
280 // Ensure two unresolvable types are not treated as equivalent
281 if (l.isUnresolvable || r.isUnresolvable) return "none"
282 // Treat `any` as a supertype of every other type
283 if (lString === "any") return rString === "any" ? "equality" : "supertype"
284 if (rString === "any") return "subtype"
285 // Otherwise, determine if the types are equivalent by checking mutual assignability
286 const checker = getInternalTypeChecker()
287 const isSubtype = checker.isTypeAssignableTo(l, r)
288 const isSupertype = checker.isTypeAssignableTo(r, l)
289 return (
290 isSubtype ?
291 isSupertype ? "equality"
292 : "subtype"
293 : isSupertype ? "supertype"
294 : "none"
295 )
296}
297
298export const checkDiagnosticMessages = (
299 attestCall: ts.CallExpression,

Callers 1

serializeArgFunction · 0.85

Calls 2

getInternalTypeCheckerFunction · 0.90
toStringMethod · 0.65

Tested by

no test coverage detected