question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

export class A extends Promise<1> {} returns undefined for base class

See original GitHub issue

Describe the bug

Version: 12.0.0

To Reproduce

import { Project } from 'ts-morph'

const project = new Project()
const sourceFile = project.createSourceFile('test.ts', `export class A extends Promise<1>,  {}`)

// reproduce the problem here
console.log(sourceFile.getClasses()[0].getBaseClass()?.getText()) // undefined

Expected behavior

It should get the Promise class.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dsherretcommented, Mar 13, 2022

Use getBaseTypes() since Promise is not defined as a class declaration and target at least es2015 by specifying the target compiler option or whatever other compiler options would cause that promise es2015 lib file to be included.

1reaction
dsherretcommented, Mar 11, 2022

It’s a little ambiguous what an additional helper method could return here. The getBaseClass() is intended to be a helper method for when the base is a class declaration because .getBaseTypes() is a little too low level for those simple situations. For this situation the recommended method to use is .getBaseTypes() and then you can decide if you want to get all the interfaces or just the variable declaration out of it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'this' returns undefined in extended Classes in Javascript
The issue is that you are calling get() on the class itself, instead of calling it on an instance of the class. Try...
Read more >
extends - JavaScript - MDN Web Docs - Mozilla
The extends keyword is used in class declarations or class expressions to create a class that is a child of another class.
Read more >
Add explicit error to __extends when base class is undefined
We occasionally get people in the IRC channel asking about their transpiled JS failing with TypeError: undefined is not an object.
Read more >
Documentation - Classes - TypeScript
Classes may extend from a base class. A derived class has all the properties and methods of its base class, and also define...
Read more >
Classes - ts-morph
Get the base class: const baseClass = classDeclaration.getBaseClass(); // returns: ClassDeclaration | undefined. Note: This is not a useful method to use if ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found