export class A extends Promise<1> {} returns undefined for base class
See original GitHub issueDescribe 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:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Use
getBaseTypes()
sincePromise
is not defined as a class declaration and target at least es2015 by specifying thetarget
compiler option or whatever other compiler options would cause that promise es2015 lib file to be included.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.