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.

create-react-app enforces @typescript-eslint/no-namespace, a style rule

See original GitHub issue

Describe the bug

  1. create-react-app --typescript
  2. Add a namespace in a file
  3. I get the error: ES2015 module syntax is preferred over custom TypeScript modules and namespaces.eslint(@typescript-eslint/no-namespace). There seems to be no way to turn off this rule, according to #3886.

Why this is a bug:

From https://github.com/facebook/create-react-app/issues/2157#issuecomment-301452953:

Our rules are specifically picked to not enforce style, and to only find logical mistakes.

Whether or not a namespace is used is most definitely not a choice of style and not a logical mistake. Please remove this rule or give me an option to remove this rule.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:16 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
szhucommented, Sep 11, 2019

Hey @cordasfilip! I think that this could be an unrelated issue, and I’d recommend creating a new GitHub issue to discuss that. If you think that people reading that issue should read this issue too, you can link to this issue there.

Since I’m already here, here are some thoughts that come to mind:

  • I think VSCode doesn’t run eslint on ts files by default, so that’s why VSCode isn’t showing the errors. Here are some keywords that can help you fix that.

  • If you replace location with window.location, does it work?

  • If debugging is required, it might be helpful if you could list of specific reproduction steps. When you make a new Github issue, the template will prompt you to do so.

1reaction
szhucommented, Sep 7, 2019

Btw, there’s one warning I have left. At this point I should probably explain my use case:

namespace Counter {
  interface Props {
    value: number
    setValue: (value: number) => void
  }
}

const Counter: React.FC<Counter.Props> = (props) => {
  return <div>{value}</div>
}

export default Counter

Basically, I don’t want to export/use props separately from the component.


For this example, the proposed fixes will make it work! But I’m still left with this warning:

Compiled with warnings.
  'Counter' is already defined  no-redeclare

Let me know what you think. Should no-redeclare also be removed? Is the props organization convention a bad one? Is there a way to achieve the same effect without namespaces? Also let me know if you think this is worthy of a separate issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced linting with Create React App, Typescript, and ESLint
I made this GitHub repo to demonstrate a fresh Create React App (Typescript template) application with customized linting rules added.
Read more >
no-namespace - TypeScript ESLint
Namespaces are an outdated way to organize TypeScript code. ES2015 module syntax is now preferred ( import / export ). This rule does...
Read more >
Google JavaScript Style Guide
1 Introduction. This document serves as the complete definition of Google's coding standards for source code in the JavaScript programming language.
Read more >
@typescript-eslint/eslint-plugin | Yarn - Package Manager
0 (2022-12-19). Features. eslint-plugin: [no-floating-promises] add suggestion fixer to add an 'await' (#5943 ( ...
Read more >
Always be linting your TypeScript! - Develop 1 Limited Blog
For TypeScript, we can enforce rules using eslint - and automatically format our code using prettier. There are a whole raft of style...
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