Skip to content

Commit

Permalink
Fix interface declarations for Typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
julien1619 committed May 13, 2020
1 parent 92caa35 commit 313837b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
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
11 changes: 10 additions & 1 deletion tests/src/rules/namespace.js
@@ -1,4 +1,4 @@
import { test, SYNTAX_CASES } from '../utils'
import { test, SYNTAX_CASES, getTSParsers } from '../utils'
import { RuleTester } from 'eslint'

var ruleTester = new RuleTester({ env: { es6: true }})
Expand Down Expand Up @@ -120,6 +120,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

0 comments on commit 313837b

Please sign in to comment.