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

TS error when using imported Command type #1037

Closed
marcopetreri opened this issue Sep 2, 2019 · 7 comments
Closed

TS error when using imported Command type #1037

marcopetreri opened this issue Sep 2, 2019 · 7 comments

Comments

@marcopetreri
Copy link

As described in the example below I cannot use Command type in types definitions because of this error:

Exported variable 'getBuildCommand' has or is using name 'local.Command' from external module "***/node_modules/commander/typings/index" but cannot be named

Example

import { Command } from 'commander';

export const getBuildCommand = (
   ...
) => (project: string, cmd: Command) => { ... };
@shadowspawn
Copy link
Collaborator

I was not able to reproduce this with typescript 3.6.2 and this program fragment. Someone else might recognise the error, or you could add some more context.

@fson
Copy link

fson commented Sep 17, 2019

I have made a minimal repoducible example for this issue: https://github.com/fson/commander-ts-repro.

When you compile the code using npm run build, it results in the following errror:

index.ts:3:1 - error TS4082: Default export of the module has or is using private name 'local.Command'.

@fson
Copy link

fson commented Sep 17, 2019

I also found a workaround: in some cases, the error went away after changing the exported function from an arrow function like this:

export default (program: Command) => { 

to a function expression:

export default function(program: Command) {

fson added a commit to expo/expo-cli that referenced this issue Sep 17, 2019
@shadowspawn
Copy link
Collaborator

Reproduced issue, and workaround, from @fson. (Thanks!)

Still trying to make sense of the local namespace pattern being used in the Commander definitions file.

@shadowspawn
Copy link
Collaborator

shadowspawn commented Oct 27, 2019

I've had a go at reworking the TypeScript declaration file and fixed this error, but the changes are tricky. If any TypeScript experts see this then a review of #1081 would be very welcome.

@shadowspawn
Copy link
Collaborator

Fixed in Commander v4, which has been released.

@shadowspawn
Copy link
Collaborator

I was reproducing this again and a historical note. This issue can be reproduced using TypeScript 3.8.3, but is fixed from 3.9.2.

jamiesyme pushed a commit to jamiesyme/expo-cli that referenced this issue Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants