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

Fix interface declarations for Typescript #1764

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -19,6 +19,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`newline-after-import`]: recognize decorators ([#1139], thanks [@atos1990])
- [`no-unused-modules`]: Revert "[flow] `no-unused-modules`: add flow type support" ([#1770], thanks [@Hypnosphi])
- TypeScript: Add nested namespace handling ([#1763], thanks [@julien1619])
- [`namespace`]/`ExportMap`: Fix interface declarations for TypeScript ([#1764], thanks [@julien1619])

### Changed
- TypeScript config: Disable [`named`][] ([#1726], thanks [@astorije])
Expand Down Expand Up @@ -685,6 +686,7 @@ for info on changes for earlier releases.
[#1786]: https://github.com/benmosher/eslint-plugin-import/pull/1786
[#1785]: https://github.com/benmosher/eslint-plugin-import/pull/1785
[#1770]: https://github.com/benmosher/eslint-plugin-import/pull/1770
[#1764]: https://github.com/benmosher/eslint-plugin-import/pull/1764
[#1763]: https://github.com/benmosher/eslint-plugin-import/pull/1763
[#1736]: https://github.com/benmosher/eslint-plugin-import/pull/1736
[#1726]: https://github.com/benmosher/eslint-plugin-import/pull/1726
Expand Down
5 changes: 4 additions & 1 deletion src/ExportMap.js
Expand Up @@ -543,7 +543,10 @@ ExportMap.parse = function (path, content, context) {
]
const exportedDecls = ast.body.filter(({ type, id, declarations }) =>
declTypes.includes(type) &&
(id && id.name === exportedName || declarations.find(d => d.id.name === exportedName))
(
(id && id.name === exportedName) ||
(declarations && declarations.find(d => d.id.name === exportedName))
)
)
if (exportedDecls.length === 0) {
// Export is not referencing any local declaration, must be re-exporting
Expand Down
11 changes: 11 additions & 0 deletions tests/files/typescript-declare-interface.d.ts
@@ -0,0 +1,11 @@
declare interface foo {
a: string;
}

declare namespace SomeNamespace {
type foobar = foo & {
b: string;
}
}

export = SomeNamespace
9 changes: 9 additions & 0 deletions tests/src/rules/namespace.js
Expand Up @@ -133,6 +133,15 @@ const valid = [
},
})),

...getTSParsers().map((parser) => test({
code: `import { foobar } from "./typescript-declare-interface"`,
parser: parser,
settings: {
'import/parsers': { [parser]: ['.ts'] },
'import/resolver': { 'eslint-import-resolver-typescript': true },
},
})),

...SYNTAX_CASES,
]

Expand Down