Skip to content

typescript class declaration private bug?? #29631

Closed

Description

TypeScript Version: 3.3.0-dev.201xxxxx

Search Terms:

Code

i don't sure this is idea bug or typescript bug

see this video for what i mean
https://www.youtube.com/watch?v=paEZCrRZ1Mw

when private it didn't output type <====== bug here
when protected it output type

idea: 2018.3.4
typescript: Version 3.3.0-dev.20190126

https://github.com/bluelovers/regexpp/blob/363adbbd762ea93fcf9ec6f0460de7cd204781e1/src/validator.ts#L555-L569

    private get ecmaVersion() {
        return this._options.ecmaVersion || 2018
    }


    private onLiteralEnter(start: number): void {
        if (this._options.onLiteralEnter) {
            this._options.onLiteralEnter(start)
        }
    }


    private onLiteralLeave(start: number, end: number): void {
        if (this._options.onLiteralLeave) {
            this._options.onLiteralLeave(start, end)
        }
    }

Expected behavior:

private onLiteralEnter(start: number): void;

Actual behavior:

private onLiteralEnter;

Playground Link:

Related Issues:

Activity

  1. fatcerberus commented on Jan 29, 2019

    @fatcerberus

    Not positive but I think that's probably by design. The .d.ts is meant to just be the public API; since the private stuff can't be accessed from outside the class implementation anyway (or at least, it isn't supposed to be 😉), there's no need for outside code to care about the type of private members. Technically they don't even have to be included in the declaration file.

    Is there a specific reason you need the type to be included?

  2. RyanCavanaugh commented on Jan 29, 2019

    @RyanCavanaugh
    Member

    You can't do anything with a private member, so its type is irrelevant

  3. RyanCavanaugh commented on Jan 29, 2019

    @RyanCavanaugh
    Member

    Technically they don't even have to be included in the declaration file.

    Almost true - private members are included so you don't (unknowingly) try to use the same property name for something else

  4. typescript-bot commented on Jan 31, 2019

    @typescript-bot
    Contributor

    This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  5. bluelovers commented on Feb 5, 2019

    @bluelovers
    ContributorAuthor

    i think should output private too like old version do, because need to check type is correct or as expected

    or give a new option for it

  6. fatcerberus commented on Feb 5, 2019

    @fatcerberus

    I don’t understand - the private member isn’t accessible from outside the class body (you will get an error if you try). What purpose does it serve to expose the type info to outside callers?

    If this is for some kind of reflection then I still don’t understand because the type can’t be checked at runtime anyway - the type info is erased.

  7. bluelovers commented on Feb 5, 2019

    @bluelovers
    ContributorAuthor

    im not wanna call it from outside, but i wanna see the type declaration, because need to debug

    because i still will use it inside at current class

    if thinking private member is no need to show, why show it name at class, why not just hidden name too?

  8. fatcerberus commented on Feb 5, 2019

    @fatcerberus

    The .d.ts isn’t for your internal use - it’s for outside callers to get the type info. If you’re calling something from inside the class then the info comes directly from the .ts.

  9. RyanCavanaugh commented on Feb 5, 2019

    @RyanCavanaugh
    Member

    if thinking private member is no need to show, why show it name at class, why not just hidden name too?

    #29631 (comment)

  10. bluelovers commented on Feb 5, 2019

    @bluelovers
    ContributorAuthor

    the javascript already will stop we use same name in class member

    but anyway , hope can have a option display private type, so we can sure everything as expected

    private onLiteralEnter(start: number): void;

    or at least should show sign like old version

    private onLiteralEnter(start);

    not only the name

    private onLiteralEnter;
  11. buttilda commented on Jan 8, 2020

    @buttilda

    You can't do anything with a private member, so its type is irrelevant

    That's not true Ryan Cavanaugh (@RyanCavanaugh).

    This properly catches the error:

    class MyClass<T> {
      private field: T;
    }
    
    // Type 'MyClass<number>' is not assignable to type 'MyClass<string>'.
    //  Type 'number' is not assignable to type 'string'
    const value: MyClass<string> = new MyClass<number>();

    This doesn't:

    class MyClass<T> {
      private field;
    }
    
    // all good 👌
    const value: MyClass<string> = new MyClass<number>();
  12. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions