Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completions for private members appear in JavaScript files #34934

Closed
jessetrinity opened this issue Nov 6, 2019 · 5 comments · Fixed by #38734
Closed

Completions for private members appear in JavaScript files #34934

jessetrinity opened this issue Nov 6, 2019 · 5 comments · Fixed by #38734
Assignees
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Domain: JavaScript The issue relates to JavaScript specifically Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@jessetrinity
Copy link
Contributor

jessetrinity commented Nov 6, 2019

When a .d.ts file is included with a .js file (ostensibly created by some .ts file in a galaxy far far away) in order to get intellisense, private class members appear in completions lists. This is probably a bug and we have gotten some feedback from users that they would rather not see this.

A possibly greater pain point is that when the private member shows up in completion, the icon is wrong, I'm guessing because we do not have the full signature for private members in .d.ts files. I believe the lack of full signatures is by design though and I don't believe there is a way to make those members appear method-like without them.

TypeScript Version: 3.6.3

Search Terms:
private completion

Code

.d.ts

// @filename:test.d.ts
/** The 'Test' namespace. */
declare namespace Test {
    /** The 'Foo' class.*/
    class Foo {
        /** Constructor. */
        constructor();
        /** I'm private: don't use me. */
        private MethodOne;
        /** I'm public: let's do this. */
        MethodTwo(): void;
    }
}

.js

// @filename:file.js
var foo = new Test.Foo();
foo.

Expected behavior:
The completion list contains MethodTwo.

Actual behavior:
The completion list contains MethodOne and MethodTwo.

@orta
Copy link
Contributor

orta commented Nov 6, 2019

Yeah, I agree - want to pair on this with me?

@Jolg42
Copy link

Jolg42 commented Jan 20, 2020

Hi there :)

So it looks like this bug is still present in the latest stable version, what is the status on your end? Would this be fixed soon maybe?

This bug is quite annoying for developer experience as a library author because it's suggesting to developers that it is fine to use the private properties (and it's adding a lot of noise to the public ones). Most people won't even know they are actually private. So if they start using them and an internal change breaks these, it will impact the users of the library, even though it's not a real breaking change in the user-facing API.

@DanielRosenwasser DanielRosenwasser added Domain: Completion Lists The issue relates to showing completion lists in an editor Domain: JavaScript The issue relates to JavaScript specifically Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this labels Jan 20, 2020
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 3.9.0 milestone Jan 20, 2020
@DanielRosenwasser
Copy link
Member

Go for it - language service tests are in tests/cases/fourslash, look for // @filename comments to create mixed a mixed .js and .ts context. The core logic is in src/services/, probably in a file called completions.ts.

@Jolg42
Copy link

Jolg42 commented Jun 3, 2020

Hi @jessetrinity, will this be in a future 3.9.x release maybe? Or like the milestone suggests the 4.0 August release?

@jessetrinity
Copy link
Contributor Author

@Jolg42 it should be in 4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor Domain: JavaScript The issue relates to JavaScript specifically Effort: Moderate Requires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual". Help Wanted You can do this Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants