dsherret / ts-morph

TypeScript Compiler API wrapper for static analysis and programmatic code changes.
https://ts-morph.com
MIT License
4.89k stars 194 forks source link

Type#getTypeArguments() weird behaviour #631

Open philipp-sorin opened 5 years ago

philipp-sorin commented 5 years ago

Version: 2.2.0

Overview

Type#getTypeArguments() returns first subclass as instance of TypeParameter At least when it was got as ClassDeclaration#getExtends().getType()

Sampe


//file Parent.ts
export class Parent {

} 

//file Child.ts 

import { Parent } from "./Parent"
class Child extends Parent {
}

// file Plugin.ts 
const project = new Project();
const sf = project.getSourceFile("Child.ts");

const ta = sf.getClasses()[0].getExtends().getType().getTypeArguments();

console.assert(ta.length === 0, "Something weird :( ");

Expected behavior Seems like it shouldn't return any type arguments

dsherret commented 5 years ago

This is all compiler api behaviour so it's probably working ok. Looks like the type argument passed down is the this type. I'll look into this more later.