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.

Incorrect generated types & fix for "eslint@typescript-eslint/unbound-method" error

See original GitHub issue

vue & vue-i18n version

ex:

  • vue: 3.0.5
  • vue-i18n: 9.0.0-rc.4

What is actually happening?

Hi there! I’m testing the new package version and I got stuck for a while on a couple of problems related to the generated types:

  • declare keyword used on type and interface exports, which has no effect (AFAIK)
  • declaration of useI18n functions using method style (t(): string) instead of property style (t: () => string), which causes a “eslint@typescript-eslint/unbound-method” linting error when destructured

The first problem shouldn’t have any side effect, it’s just pointless: declare keyword has no effect when used in that way. You should probably remove those anyway, just to be sure.

The second one would force anyone using TypeScript linter to disable an error every time the composable is used. I guess you defined those using the method notation to be able to add overloads, but TS assume that functions on object defined with method notation MIGHT be using the local context, that’s why the linter then complains about this. You can accomplish the same thing by declaring those functions and overloads at root level, then adding a property with the function name and with type as the typeof of the declared function.

Example:

declare function t(key: Path | number): string;
declare  function t(key: Path | number, plural: number, options?: TranslateOptions): string;
declare function t(key: Path | number, defaultMsg: string, options?: TranslateOptions): string;
// Other overloads

export interface Composer<Messages = {}, DateTimeFormats = {}, NumberFormats = {}, Message = VueMessageType> {
    // other properties
    t: typeof t;
    // other properties
}

I tried this out on-the-fly and it seems to work correctly. Other Vue3-ready packages I used doesn’t seem to share this problem

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
IlCallocommented, Jan 27, 2021

I prefer that you would like to use eslint-disable (e.g. /* eslint-disable-line @typescript-eslint/unbound-method */) to work around it.

We surely can, but this means everyone using this package with Composition API and TypeScript will have to disable that rule every time it’s destructured (or disable it altogether, which isn’t really acceptable). This translates to using it nearly many times as the number of your components (if you’re using pure Composition API style you suggest).

It seems strange all composables from other Vue ecosystem packages don’t have this problems, and some of them use api-extractor too (eg. vue itself). Maybe they had the same problem at some point and found a way to workaround this?

Anyway, I understand you don’t want to mess things up right now, it’s more a DX problem. Since I was exploring this to write Quasar 2 migration guide, I’ll just suggest everyone with the problematic setup to stick to the legacy API (if possible) or disable the rule inline

Thanks for looking into this anyway!

0reactions
IlCallocommented, Apr 5, 2022

This seems resolved in latest 9.2 beta version

Read more comments on GitHub >

github_iconTop Results From Across the Web

8.0.0 Failed to load plugin '@typescript-eslint' - Stack Overflow
I saw this error trying to use version 4.x.x of the @typescript-eslint packages:
Read more >
valid-jsdoc - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
How to use ESLint with TypeScript | Khalil Stemmler
ESLint is a JavaScript linter that you can use to lint either TypeScript or JavaScript code. In this post, we'll walk through how...
Read more >
Linting in TypeScript using ESLint and Prettier - LogRocket Blog
Integrate Prettier with ESLint to automate type-checking in your TypeScript code and ensure that the code has no bugs.
Read more >
ESLint | PhpStorm Documentation - JetBrains
Besides JavaScript and TypeScript, ESLint can be applied to files of ... To resolve the detected problem, click ESLint: Fix '<rule name>' or ......
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