Skip to content

Generic type parameters considered private in protected methods when generating .d.ts #1445

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

Closed
jctitor opened this issue Dec 11, 2014 · 8 comments · Fixed by #1614
Closed
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@jctitor
Copy link

jctitor commented Dec 11, 2014

The following code fails in TypeScript 1.4 with the below errors:

export class MyClass {
    protected myMethod<T>(val: T): T {
        return val;
    }
}

Parameter 'val' of public method from exported class has or is using private name 'T'.
Return type of public method from exported class has or is using private name 'T'.

@mhegazy mhegazy added the Bug A bug in TypeScript label Dec 11, 2014
@danquirk
Copy link
Member

I'm not seeing this on the latest bits. Is there something more to the repro?

@mhegazy mhegazy removed the Bug A bug in TypeScript label Dec 11, 2014
@jctitor
Copy link
Author

jctitor commented Dec 11, 2014

I apologize, this only manifests if "Generate declaration files" is selected for the project.

@danquirk
Copy link
Member

Ah, there we go :)

@danquirk danquirk changed the title Generic type parameters considered private in protected methods Generic type parameters considered private in protected methods when generating .d.ts Dec 11, 2014
@mhegazy mhegazy added the Bug A bug in TypeScript label Dec 11, 2014
@mhegazy mhegazy added this to the TypeScript 1.5 milestone Dec 11, 2014
@jctitor
Copy link
Author

jctitor commented Dec 19, 2014

This issue is a mismatch between the checker visibility rules and the emitter output rules.

The checker's determineIfDeclarationIsVisible function considers a Protected method to be not visible. However, the emitter's emitParameterDeclaration and emitSignatureDeclaration functions will emit parameter/return types for non-Private methods. Thus protected methods cause emitting of a non-visible type, resulting in a "of_public_method_from_exported_class_has_or_is_using_private_name" class of error.

I don't have sufficient knowledge of the codebase to submit a PR, but time-permitting it would be fantastic if a fix could make it into the 1.4 release. Our organization relies on .d.ts generation as a means of simulating .dlls, such that we can depend on a common set of "library" projects for our various application projects. This defect would in many instances prevent using protected in such libraries.

@danquirk
Copy link
Member

danquirk commented Jan 6, 2015

This was broken by 1.4, it worked in 1.3.

@bluong
Copy link

bluong commented Jan 7, 2015

We have an issue arising from the fact that this worked in 1.3 but not in 1.4. Is it possible for a fix for this to be made for the 1.4 release. Otherwise, we're gonna have a back-compat break.

@vladima vladima added the Fixed A PR has been merged for this issue label Jan 7, 2015
@RyanCavanaugh
Copy link
Member

Referenced PR got cherry-picked into 1.4

@derekcicerone-zz
Copy link

Awesome, thanks for the quick fix!

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants