No generic type on SourceFileBase in typings
See original GitHub issueDescribe the bug
Version: 2.1.0
Excerpt from the typings starting at line 7475:
declare const SourceFileBase: Constructor<ModuledNode> & Constructor<StatementedNode> & Constructor<TextInsertableNode> & typeof Node;
export declare class SourceFile extends SourceFileBase<ts.SourceFile> {
When SourceFile is declared it is said to extend SourceFileBase of generic type ts.SourceFile. But accordinmg to the declaration above SourceFileBase does not support a generic type. This leads to to for example Intellij/Webstorm to not include any of the properties from SourceFileBase in its completion for SourceFile. Many other tools do support this and so this might also be an issue on JetBrains side, but I thought it worth bringing up to make sure this was intentional.
To Reproduce
Adding steps to reproduce doesn’t make 100% sense here but I’m still going to do it.
Add the code below into a TSMorph project and open it in IntelliJ or Webstorm.
import { Project } from "ts-morph";
const project = new Project();
const sourceFile = project.createSourceFile("test.ts", ``);
sourceFile.addVariableStatement({
declarationKind: VariableDeclarationKind.Const,
declarations: [{
name: "myNumber",
initializer: "5"
}
});
The IDE will not understand that addVariableStatement is present on SourceFile. If you now go into the typings for TS Morph and on line 7477 remove the generic type <ts.SourceFile>, it will recognize that addVariableStatement and various other properties are present on SourceFile.
Expected behavior
Expected behavior is that the methods from ModuledNode, StatementedNode & TextInsertableNode show up in completion in all IDEs, but it might also be that IntelliJ has a bug here 😉
Sorry if this issue is nuisance and SourceFileBase<ts.SourceFile>
makes total sense.
Thanks a lot for building this great library.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
@dsherret interesting… I was still on 2018.2.x. Just updated to the same version as you (2019.1.2) and it seems to be resolved. I’m also not having the issue where it stops showing up if you type enough of the method name.
Thanks!
@arxenix @LeonardKoch I just tried this out in WebStore 2019.1.2 (WS-191.7141.49 – May 7th) and it seems to work fine now. What versions are you using?
What I did find, is it takes about a second for the completion list to populate entirely with WebStorm. I also found that if I typed enough of the method name it wouldn’t show up at all.
So I’m going to close this as it seems to be working now. Hopefully the experience WebStorm will continue to improve and I’m glad to hear it’s not as much of a pain as I found it to be 3 years ago.