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

Exported variable <variable name> has or is using private name <private name> from external library #15947

Closed
ryasmi opened this issue May 19, 2017 · 11 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@ryasmi
Copy link

ryasmi commented May 19, 2017

Hey guys not really sure what to do about this. I know this is a duplicate of #6307, but I didn't really want to comment on a closed issue. I can't really use @DanielRosenwasser's solution here because the class is exported from the library. I guess I could extend that class in my code and use that instead. Completely understand the issues with this, I guess I'm just looking for a recommendation and I wanted to report this for other people.

Error:

(4,1): error TS4082: Default export of the module has or is using private name 'Warning'.

My code:

import { optional } from 'rulr';
import { stringValue, mailto, sha1, iri, account } from '../factory';

export default {
  objectType: optional(stringValue),
  name: optional(stringValue),
  mbox: optional(mailto),
  mbox_sha1sum: optional(sha1),
  openid: optional(iri),
  account: optional(account),
};

Rulr's type definitions (generated by the TypeScript compiler):

export declare type Path = string[];
export declare class Warning {
    data: any;
    path: Path;
    constructor(data: any, path: Path);
}
export declare type Rule = (data: any, path: Path) => Warning[];
export declare const optional: (rule: Rule) => Rule;
@ryasmi
Copy link
Author

ryasmi commented May 19, 2017

Actually I can't extend the class, that makes no sense. I'd have to recreate every function in that library haha

@ryasmi
Copy link
Author

ryasmi commented May 19, 2017

Ok as to the rescue haha, I don't think this is ideal, but it does work.

import { optional, Rule } from 'rulr';
import { stringValue, mailto, sha1, iri, account } from '../factory';

export default {
  objectType: optional(stringValue) as Rule,
  name: optional(stringValue),
  mbox: optional(mailto),
  mbox_sha1sum: optional(sha1),
  openid: optional(iri),
  account: optional(account),
};

@mhegazy
Copy link
Contributor

mhegazy commented May 19, 2017

I am not able to get this to repro locally using your input file. can you share more context?

@mhegazy mhegazy added the Needs More Info The issue still hasn't been fully clarified label May 19, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Jun 4, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Jun 4, 2017
@ryasmi
Copy link
Author

ryasmi commented Jun 4, 2017

Hey @mhegazy, no worries, I'd do the same, I'm on holiday for a few more days, I'll get back to this when I'm home 😄

@ryasmi
Copy link
Author

ryasmi commented Jun 14, 2017

Ok @mhegazy, what context do you need? 😄

@mhegazy
Copy link
Contributor

mhegazy commented Jun 15, 2017

can you share a self-contained sample that reproduces the issue?

@ryasmi
Copy link
Author

ryasmi commented Jun 15, 2017

Yeah I'll give that a try.

@ryasmi
Copy link
Author

ryasmi commented Jun 15, 2017

@mhegazy
Copy link
Contributor

mhegazy commented Jun 15, 2017

This is the same issue as #9944. The declaration emitter tried to serialize the type of the property foobar, which is Rule, which is an alias to (data: any, path: Path) => Warning[];, it tried to write Warning but that would be invalid, since Warning is not imported.
The emitter does not add imports automatically to avoid divulging implementation details that the user did not intend to expose. #9944 tracks relaxing this rule.

To avoid this warning, write an explicit type annotation for the type of your property. something like this would work:

import { optional, Rule } from 'rulr';

export default <{foobar: Rule;}> {
  foobar: optional(() => []),
}

@ryasmi
Copy link
Author

ryasmi commented Jun 16, 2017

Hey @mhegazy, I did understand that already from other issues I'd found before creating this one, but thank you for the explanation anyway and thanks for referencing the duplicate issue (sorry I didn't find that in my search) 😄 I'll subscribe to that issue going forward.

Thanks for the fix too! 👍

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

2 participants