You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
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.
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.
classMyClass<T>{privatefield: T;}// Type 'MyClass<number>' is not assignable to type 'MyClass<string>'.// Type 'number' is not assignable to type 'string'constvalue: MyClass<string>=newMyClass<number>();
This doesn't:
classMyClass<T>{privatefield;}// all good 👌constvalue: MyClass<string>=newMyClass<number>();
Activity
fatcerberus commentedon Jan 29, 2019
Not positive but I think that's probably by design. The
.d.tsis 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?
RyanCavanaugh commentedon Jan 29, 2019
You can't do anything with a private member, so its type is irrelevant
RyanCavanaugh commentedon Jan 29, 2019
Almost true - private members are included so you don't (unknowingly) try to use the same property name for something else
typescript-bot commentedon Jan 31, 2019
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
bluelovers commentedon Feb 5, 2019
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
fatcerberus commentedon Feb 5, 2019
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.
bluelovers commentedon Feb 5, 2019
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?
fatcerberus commentedon Feb 5, 2019
The
.d.tsisn’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.RyanCavanaugh commentedon Feb 5, 2019
#29631 (comment)
bluelovers commentedon Feb 5, 2019
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
or at least should show sign like old version
not only the name
buttilda commentedon Jan 8, 2020
That's not true Ryan Cavanaugh (@RyanCavanaugh).
This properly catches the error:
This doesn't: