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

[init-declarations] It report Variable 'b' should be initialized on declaration. when I declare nested namespace in a index.d.ts file #4392

Closed
3 tasks done
drylint opened this issue Jan 6, 2022 · 2 comments · Fixed by #4544
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@drylint
Copy link

drylint commented Jan 6, 2022

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "rules": {
    "init-declarations": [0],
    "@typescript-eslint/init-declarations": [2, "always"],
  }
}
// index.d.ts

// eg.1
declare namespace obj {
  const a: number
}

// eg.2
declare namespace obj1 {
  declare const a: number
  namespace obj1_1 {
    const b: string // Error info: Variable 'b' should be initialized on declaration.
  }
}

// eg.3
declare namespace obj2 {
  const a: number
  namespace obj2_2 {
    declare const b: string
  }
}

Expected Result

Expected that don't report error with const b: string in eg.2

Actual Result

eg.1 and eg.3 is OK, but eg.2 was reported Variable 'b' should be initialized on declaration.

image

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 5.8.1
@typescript-eslint/parser 5.8.1
TypeScript 4.5.4
ESLint 8.5.0
node 16.13.1
@drylint drylint added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Jan 6, 2022
@drylint drylint changed the title [init-declarations] It report an error when I declare nested namespace in a index.d.ts file [init-declarations] It report Variable 'b' should be initialized on declaration. when I declare nested namespace in a index.d.ts file Jan 6, 2022
@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working and removed triage Waiting for maintainers to take a look labels Jan 6, 2022
@lonyele
Copy link
Contributor

lonyele commented Feb 12, 2022

@JoshuaKGoldberg
Copy link
Member

Yup. In theory this is why it's generally preferable to post playground links like that one 👆 instead of screenshots.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants