private _validateHeritageClauses()

in src/assembler.ts [939:970]


  private _validateHeritageClauses(clauses?: ts.NodeArray<ts.HeritageClause>) {
    if (clauses == null || clauses.length === 0) {
      // Nothing to do.
      return;
    }
    for (const clause of clauses) {
      for (const node of clause.types) {
        const parentType = this._typeChecker.getTypeAtLocation(node);
        if (parentType.symbol == null) {
          // The parent type won't have a symbol if it's an "error type" inserted by the type checker when the original
          // code contains a compilation error. In such cases, the TypeScript compiler will already have reported about
          // the incoherent declarations, so we'll just not re-validate it there (we'd fail anyway).
          continue;
        }
        // For some reason, we cannot trust parentType.isClassOrInterface()
        const badDecl = parentType.symbol.declarations?.find(
          (decl) =>
            !ts.isClassDeclaration(decl) && // <-- local classes
            !ts.isInterfaceDeclaration(decl) && // <-- local interfaces
            !ts.isModuleDeclaration(decl), // <-- imported types
        );
        if (badDecl != null) {
          this._diagnostics.push(
            JsiiDiagnostic.JSII_3004_INVALID_SUPERTYPE.create(node, clause, badDecl).addRelatedInformation(
              badDecl,
              'The invalid super type is declared here.',
            ),
          );
        }
      }
    }
  }