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.

bug in @types/stopword, plus Typescript access

See original GitHub issue

Not sure if you maintain @types/stopword, but I think it has a bug in it:

...
export const it: string[];
export const ja: string[];
export const ko: string[];
export const la: string;
export const lgg: string[];
export const lggo: string[];
export const lv: string[];
...

As you see sw.la is a string and not a string[]. Reporting here because definitely typed is a massive monorepo.

Also, I wasn’t able to use sw[language] to get the stopwords list for a given language. So I wrote this crazy function to do it. Is there an easier way for Typescript users? If not, you might include this in your library.

Thanks for all the work on this!

import sw from 'stopword';

export const getStopwords = (language: string): string[] | undefined => {
  switch (language) {
    case 'af': {
      return sw.af;
    }
    case 'ar': {
      return sw.ar;
    }
    case 'bg': {
      return sw.bg;
    }
    case 'bn': {
      return sw.bn;
    }
    case 'br': {
      return sw.br;
    }
    case 'ca': {
      return sw.ca;
    }
    case 'cs': {
      return sw.cs;
    }
    case 'da': {
      return sw.da;
    }
    case 'de': {
      return sw.de;
    }
    case 'el': {
      return sw.el;
    }
    case 'en': {
      return sw.en;
    }
    case 'eo': {
      return sw.eo;
    }
    case 'es': {
      return sw.es;
    }
    case 'et': {
      return sw.et;
    }
    case 'eu': {
      return sw.eu;
    }
    case 'fa': {
      return sw.fa;
    }
    case 'fr': {
      return sw.fr;
    }
    case 'fi': {
      return sw.fi;
    }
    case 'ga': {
      return sw.ga;
    }
    case 'gl': {
      return sw.gl;
    }
    case 'ha': {
      return sw.ha;
    }
    case 'he': {
      return sw.he;
    }
    case 'hi': {
      return sw.hi;
    }
    case 'hr': {
      return sw.hr;
    }
    case 'hu': {
      return sw.hu;
    }
    case 'hy': {
      return sw.hy;
    }
    case 'id': {
      return sw.id;
    }
    case 'it': {
      return sw.it;
    }
    case 'ja': {
      return sw.ja;
    }
    case 'ko': {
      return sw.ko;
    }
    case 'la': {
      // bug in @types/stopword
      return sw.la as unknown as string[];
    }
    case 'lgg': {
      return sw.lgg;
    }
    case 'lggo': {
      return sw.lggo;
    }
    case 'lv': {
      return sw.lv;
    }
    case 'mr': {
      return sw.mr;
    }
    case 'my': {
      return sw.my;
    }
    case 'nl': {
      return sw.nl;
    }
    case 'no': {
      return sw.no;
    }
    case 'pa': {
      return sw.pa;
    }
    case 'pl': {
      return sw.pl;
    }
    case 'pt': {
      return sw.pt;
    }
    case 'ptbr': {
      return sw.ptbr;
    }
    case 'ro': {
      return sw.ro;
    }
    case 'ru': {
      return sw.ru;
    }
    case 'sk': {
      return sw.sk;
    }
    case 'sl': {
      return sw.sl;
    }
    case 'so': {
      return sw.so;
    }
    case 'st': {
      return sw.st;
    }
    case 'sv': {
      return sw.sv;
    }
    case 'sw': {
      return sw.sw;
    }
    case 'th': {
      return sw.th;
    }
    case 'tr': {
      return sw.tr;
    }
    case 'vi': {
      return sw.vi;
    }
    case 'yo': {
      return sw.yo;
    }
    case 'zh': {
      return sw.zh;
    }
    case 'zu': {
      return sw.zu;
    }
  }
  return undefined;
};

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
peterblazejewiczcommented, Apr 29, 2022

fyi: DefinitelyTyped/DefinitelyTyped#60121

3reactions
peterblazejewiczcommented, May 16, 2021

folks, sorry, it was a exemplary typo. I’ve updated types, to use a list of language codes now, so it should be easier to spot similar issue next time, thx!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bug Workbench - TypeScript
The bug workbench lets you make reproductions of bugs which are trivial to verify against many different versions of TypeScript over time. A...
Read more >
7 Common Bugs in TypeScript (and JavaScript)
Here, you will learn how programmers can make innocent mistakes which impact the correctness of code in TypeScript and JavaScript, and lead to...
Read more >
Is this behavior of "𝚊𝚗𝚢" a TypeScript Type System Bug?
The point of the any type is to opt out of type checking for some parts of your code. It is intentionally unsound;...
Read more >
TypeScript and React - how to prevent bugs by typing props ...
TypeScript is fantastic to use with React because it can help us catch a lot of bugs we wouldn't catch otherwise.
Read more >
bug(esm): TypeScript is not an ECMAScript superset post ...
This bug report will show that TypeScript is no longer an ECMAScript subset as of ES2015 due to its refusal to support import...
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