question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expected behavior is unclear when using types and non-camelcase

See original GitHub issue

Hello!

I came across a gotcha and wanted to document it for future users of this library.

As demonstrated by this sandbox https://codesandbox.io/s/meow-kebab-case-behavior-9rpoc, the type hints are inconsistent with the actual shape of the parsed object. The code below is from the sandbox to demonstrate:

import meow from "meow";

const cli = meow("", {
  flags: {
    "input-file": {
      type: "string",
      alias: "i",
      default: "INPUT"
    }
  }
});

const camel = cli.flags.inputFile;
const kebab = cli.flags["input-file"];

type C = typeof camel; // unknown
type K = typeof kebab; // string;

console.log(camel, kebab);
// yet this outputs:
// > INPUT undefined

This leads to some tricky behavior when using meow, TS, and normalized names. Specifically, type hints and autocompletion will show cli.flags['input-file'] as the type-safe suggestion, when it’s actually undefined.

I don’t think it’s possible for meow to handle this due to how TS generics work. But hopefully this saves someone else time that I spent trying to figure this out 😄 Unfortunately I don’t know of a type-safe workaround.

And there’s always the chance I’m doing something wrong, and if so, sorry for the noise. Thanks for the library!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
sindresorhuscommented, Nov 25, 2020
1reaction
Robbie-Cookcommented, Nov 25, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

zsh-config/_rust at master - GitHub
"2[full debug info with variable and type information (same as -g)]". ) ... The passes specified are appended at the end of the...
Read more >
VS Code: How to convert snippet placeholder from ...
I would like to have a snippet with placeholder that expects camelCase and then transform a matching placeholder to SCREAMING_SNAKE_CASE. Here's ...
Read more >
Warn-by-default Lints - The rustc book
This lint is issued if you pass in a value with a smaller data type than the default register size, to alert you...
Read more >
Conformity in Psychology: Definition, Types, & Examples
This usually occurs when a person lacks knowledge and looks to the group for guidance. Or when a person is in an ambiguous...
Read more >
How to make movements respect camelCase or snake_case?
Using d,w will remove camel ; using it again will remove Case . ... "Inner" motions (such as diw ) should also work...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found