Skip to content

Commit 40ee069

Browse files
julien1619ljharb
authored andcommitted
[Fix] namespace/ExportMap: Fix interface declarations for TypeScript
See also #1528.
1 parent eb2b7ea commit 40ee069

File tree

4 files changed

+26
-1
lines changed

4 files changed

+26
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
1919
- [`newline-after-import`]: recognize decorators ([#1139], thanks [@atos1990])
2020
- [`no-unused-modules`]: Revert "[flow] `no-unused-modules`: add flow type support" ([#1770], thanks [@Hypnosphi])
2121
- TypeScript: Add nested namespace handling ([#1763], thanks [@julien1619])
22+
- [`namespace`]/`ExportMap`: Fix interface declarations for TypeScript ([#1764], thanks [@julien1619])
2223

2324
### Changed
2425
- TypeScript config: Disable [`named`][] ([#1726], thanks [@astorije])
@@ -685,6 +686,7 @@ for info on changes for earlier releases.
685686
[#1786]: https://github.com/benmosher/eslint-plugin-import/pull/1786
686687
[#1785]: https://github.com/benmosher/eslint-plugin-import/pull/1785
687688
[#1770]: https://github.com/benmosher/eslint-plugin-import/pull/1770
689+
[#1764]: https://github.com/benmosher/eslint-plugin-import/pull/1764
688690
[#1763]: https://github.com/benmosher/eslint-plugin-import/pull/1763
689691
[#1736]: https://github.com/benmosher/eslint-plugin-import/pull/1736
690692
[#1726]: https://github.com/benmosher/eslint-plugin-import/pull/1726

src/ExportMap.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,10 @@ ExportMap.parse = function (path, content, context) {
543543
]
544544
const exportedDecls = ast.body.filter(({ type, id, declarations }) =>
545545
declTypes.includes(type) &&
546-
(id && id.name === exportedName || declarations.find(d => d.id.name === exportedName))
546+
(
547+
(id && id.name === exportedName) ||
548+
(declarations && declarations.find(d => d.id.name === exportedName))
549+
)
547550
)
548551
if (exportedDecls.length === 0) {
549552
// Export is not referencing any local declaration, must be re-exporting
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare interface foo {
2+
a: string;
3+
}
4+
5+
declare namespace SomeNamespace {
6+
type foobar = foo & {
7+
b: string;
8+
}
9+
}
10+
11+
export = SomeNamespace

tests/src/rules/namespace.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ const valid = [
133133
},
134134
})),
135135

136+
...getTSParsers().map((parser) => test({
137+
code: `import { foobar } from "./typescript-declare-interface"`,
138+
parser: parser,
139+
settings: {
140+
'import/parsers': { [parser]: ['.ts'] },
141+
'import/resolver': { 'eslint-import-resolver-typescript': true },
142+
},
143+
})),
144+
136145
...SYNTAX_CASES,
137146
]
138147

0 commit comments

Comments
 (0)