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.

No generic type on SourceFileBase in typings

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
arxenixcommented, May 21, 2019

@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!

0reactions
dsherretcommented, May 20, 2019

@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.

delete

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"TypeVar bound type cannot be generic" reported for non
Pylance reports "TypeVar bound type cannot be generic" when using typing.TypeVar and specifying, for the bound= parameter, a non-generic ...
Read more >
Unable to assign function to type with generic parameter
Typescript gives the following error: Type '(v: string[]) => string' is not assignable to type '(v: T) => string'. Types of parameters ...
Read more >
SCons User Guide 1.3.0
Type : 'scons program' to build the production program. Use scons -H for help about command-line options. If there is no Help text...
Read more >
Online Help - Amazon AWS
The Cleo VLTrader application supports varying tree node types, including generic and customized FTP, HTTP, and.
Read more >
GNAT User's Guide for Native Platforms
3.9.3.3 Creating a Stand-alone Library to be used in a non-Ada context. ... Compile generic units in the same manner as any other...
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