-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Private methods in d.ts files should be declared with rest parameters to make them more stable #10438
Comments
I am just wondering why the generated declaration file .d.ts even contains private members. |
@RyanCavanaugh Ok I understand the purpose of letting private members in d.ts files for avoiding some weird bugs. |
@RyanCavanaugh we use d.ts file to compute the impact of upwards compilation between modules. If the 'public' shape of a module doesn't change the modules that depend on it don't need to be recompiled. According to the discussion in #1867 names of private members belong to the public shape however not its full signature. Rest params allow to only put the minimal necessary information into the shape to achieve this. |
A builder that would profit from this can be found here: https://github.com/Microsoft/TypeScript/tree/dbaeumer/9125 |
Why doesn't your difference-computer simply ignore the types of private members? That's going to be a more comprehensive fix, especially because e.g. changing something from a method to an arrow function is going to show up as a difference. |
i agree with @RyanCavanaugh, the fix here is not to change the .d.ts emit output, but rather to optimize the public API shape differ. today it uses the .d.ts output, but there is no reason it can not be a separate output. |
OK. I take the point of making the differ of the shape aware of this. But why does a private signature list the param names in the first place. The only reason why the private member is in is to check for overriding the name. Adding the param names is not necessary and only leaks unnecessary information into the d.t.s file. |
Like it or not, |
I understand that private isn't private at runtime. This is exactly the reasoning behind my argument. I want to make it hard for other to call my private members. The more information we leak into a d.ts the easier it is. |
I think they have your code anyway? 😕 |
So what is the reasoning behind putting the whole signature if not necessary. |
Not to go off topic, but how come we even display the method signature at all? For private properties we just display |
Personal opinion (as they all are) that isn't "lying", where as changing the arity of a method would be. Stripping all the type information might be logical: export declare class Bug {
private method(one: any, two: any): any;
} That represents what is actually in the code without any additional information. |
This is already the case. The d.t.s looks like this: export declare class Bug {
private method(one, two);
} which is implicit any. |
Accepting PRs to just emit class Bug {
method;
} |
Since the effort is easy I grabbed it and made a PR #11030 |
TypeScript Version: 1.8.0 / nightly (2.0.0-dev.201xxxxx)
Code
To make the d.ts more stable I think that the generated d.ts file should look like this:
Since the actual number of params of that method doesn't matter. All that is need is the name. This keeps the
shape
of a TS module more stable if private members change.The text was updated successfully, but these errors were encountered: