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

Flags are not working with typescript ^4.1.3 #172

Open
jpgorman opened this issue Dec 17, 2020 · 13 comments
Open

Flags are not working with typescript ^4.1.3 #172

jpgorman opened this issue Dec 17, 2020 · 13 comments

Comments

@jpgorman
Copy link

os: windows10
node: v10.15.1
terminal: WSL

const options = {
  flags: {
    rainbow: {
     type: 'boolean',
     alias: 'r'
    }
  }
}

meow(`...`, options)

image

@sindresorhus
Copy link
Owner

Try:

const options = {
  flags: {
    rainbow: {
     type: 'boolean',
     alias: 'r'
    }
  }
} as const;

meow(`...`, options)

or putting the object literal inline.

@jpgorman
Copy link
Author

Thanks for the very fast response.

I've taken a look and I can confirm that:

The first option of using const results in a syntax error.

The second option of passing the options inline does remove that type error, however I'm not getting a typed interface on the return meow object.

The problem with the second option though is that you can't then use the options outside of that function call.

@jpgorman
Copy link
Author

Would it be an option to export the options type and then use that when defining my options object e.g,

import { Options } from 'meow'

const options: Options = {
  flags: {
    rainbow: {
     type: 'boolean',
     alias: 'r'
    }
  }

@sindresorhus
Copy link
Owner

The first option of using const results in a syntax error.

Make sure you're on the latest TS version.

@jpgorman
Copy link
Author

jpgorman commented Dec 22, 2020

I'm currently using 4.1.3

sindresorhus added a commit that referenced this issue Dec 22, 2020
@sindresorhus
Copy link
Owner

This passes: a0ce744

@jpgorman
Copy link
Author

What version of typescript are you using to test types? I wasn't sure after looking at the package.json

@jpgorman
Copy link
Author

Also I check that it isn't a case of my IDE not respecting const assertions

@jpgorman
Copy link
Author

So I tried again using the const assertions approach and I was getting the same type errors.

@sindresorhus
Copy link
Owner

TS 4.1.2

@jpgorman
Copy link
Author

jpgorman commented Dec 23, 2020

Thanks for your help. I'm not sure why i'm getting such a different result. For now I've stubbed out the types for the library to get it working in my project.

@Caryyon
Copy link

Caryyon commented May 6, 2021

Getting something similar using npx create-ink-app
Screen Shot 2021-05-05 at 8 22 53 PM

@LitoMore
Copy link
Contributor

LitoMore commented May 6, 2021

The root cause is create-ink-app always using the latest version of meow and @sindresorhus/tsconfig. create-ink-app is using a simple install script to install them without a specific version. By default, you will get the latest version.

Since [email protected], we moved our package to ESM.

I will help create-ink-app move their package to ESM. It will take some time because there are some blocking dependencies that need to be moved to ESM as well.

Before that, you could downgrade your meow to 9.0.0 or lower manually (just modify your generated code and reinstall dependencies).

Update:
I submitted a quick fix for CommonJS modules.

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

4 participants