UNPKG

typir

Version:

General purpose type checking library

50 lines 1.94 kB
/****************************************************************************** * Copyright 2024 TypeFox GmbH * This program and the accompanying materials are made available under the * terms of the MIT License, which is available in the project root. ******************************************************************************/ import { isType, Type } from '../../graph/type-node.js'; import { TypeEqualityProblem } from '../../services/equality.js'; import { createKindConflict } from '../../utils/utils-type-comparison.js'; import { isTopKind } from './top-kind.js'; export class TopType extends Type { constructor(kind, identifier, typeDetails) { super(identifier, typeDetails); this.kind = kind; this.defineTheInitializationProcessOfThisType({}); // no preconditions // ensure, that all (other) types are a sub-type of this Top type: const graph = kind.services.infrastructure.Graph; graph.addListener(this, { callOnAddedForAllExisting: true }); // all upcomping types } dispose() { this.kind.services.infrastructure.Graph.removeListener(this); } onAddedType(type, _key) { if (type !== this) { this.kind.services.Subtype.markAsSubType(type, this, { checkForCycles: false }); } } getName() { return this.getIdentifier(); } getUserRepresentation() { return this.getIdentifier(); } analyzeTypeEqualityProblems(otherType) { if (isTopType(otherType)) { return []; } else { return [{ $problem: TypeEqualityProblem, type1: this, type2: otherType, subProblems: [createKindConflict(otherType, this)], }]; } } } export function isTopType(type) { return isType(type) && isTopKind(type.kind); } //# sourceMappingURL=top-type.js.map