dsherret / code-block-writer

Code writer for JavaScript and TypeScript code.
MIT License
194 stars 4 forks source link

getBaseTypes() and getBaseClass() not working #39

Closed svallory closed 3 years ago

svallory commented 3 years ago

I'm using the latest version of ts-morph, Node 16, and typescript 4.3.5

Here's the source code of the class file

import React from 'react';

export class ClassComp extends React.Component {}

And here's the test code:

  let exportedClasses: ClassDeclaration[] = project
    .getSourceFiles()
    .flatMap((file) => file.getClasses())
    .filter((c) => c.isExported());

  console.log(`Found ${exportedClasses.length} exported classes`);

  exportedClasses.forEach((c) => {
    console.log(
      `   Checking class ${c.getName()}
      base types count: ${c.getBaseTypes().length}
      Base class: ${c.getBaseClass()}
      Extends: ${c.getExtends().getText()}`,
    );
  });

Output:

Found 1 exported classes
   Checking class ClassComp
      base types count: 0
      Base class: undefined
      Extends: React.Component
dsherret commented 3 years ago

@svallory I think you accidentally logged an issue in the wrong repository.

Try checking project.getPreEmitDiagnostics() for any compile errors.

svallory commented 3 years ago

😂 Yep! Wrong repo indeed! But thanks for the answer anyways!