Skip to content

Incorrect definition emitted when an interface name collides with an imported const #68

Open
@varungandhi-src

Description

@varungandhi-src

Minimal example:

import React from 'react'

import { StepN } from './Steps'

interface Step {
  content: React.ReactElement
}

This gives 2 identifiers as you'd expect:

this.lsifSymbol(decl) {
  role: 'UnspecifiedSymbolRole',
  'ident.range': [ 2, 9, 14 ],
  'decl.kind': 'ImportSpecifier',
  'decl.range': [ 2, 9, 14 ],
  lsifSymbol: LsifSymbol {
    value: 'lsif-typescript npm @types/react 17.0.0 `index.d.ts`/React/FunctionComponent#'
  }
}
this.lsifSymbol(decl) {
  role: 'Definition',
  'ident.range': [ 4, 10, 14 ],
  'decl.kind': 'InterfaceDeclaration',
  'decl.range': [ 4, 0, 6, 1 ],
  lsifSymbol: LsifSymbol {
    value: 'lsif-typescript npm react-example 1.0.0 src/`Shadow.tsx`/Step#'
  }
}

For some reason, when you change the imported identifier to Step (so the local definition is shadowing the import), you get 3 identifiers instead of 2:

this.lsifSymbol(decl) { // 1 -- sensible
  role: 'UnspecifiedSymbolRole',
  'ident.range': [ 2, 9, 13 ],
  'ident.parent.kind': 'ImportSpecifier',
  'ident.parent.range': [ 2, 9, 13 ],
  'decl.kind': 'ImportSpecifier',
  'decl.range': [ 2, 9, 13 ],
  lsifSymbol: LsifSymbol {
    value: 'lsif-typescript npm @types/react 17.0.0 `index.d.ts`/React/FunctionComponent#'
  }
}
this.lsifSymbol(decl) { // 2
  role: 'UnspecifiedSymbolRole',
  'ident.range': [ 2, 9, 13 ],
  'ident.parent.kind': 'ImportSpecifier',
  'ident.parent.range': [ 2, 9, 13 ],
  'decl.kind': 'InterfaceDeclaration', // wrong
  'decl.range': [ 4, 0, 6, 1 ],
  lsifSymbol: LsifSymbol {
    value: 'lsif-typescript npm react-example 1.0.0 src/`Shadow.tsx`/Step#'
  }
}
this.lsifSymbol(decl) { // 3
  role: 'Definition',
  'ident.range': [ 4, 10, 14 ],
  'ident.parent.kind': 'InterfaceDeclaration',
  'ident.parent.range': [ 4, 0, 6, 1 ],
  'decl.kind': 'ImportSpecifier', // wrong
  'decl.range': [ 2, 9, 13 ],
  lsifSymbol: LsifSymbol {
    value: 'lsif-typescript npm @types/react 17.0.0 `index.d.ts`/React/FunctionComponent#'
  }
}

This means that at the definition of interface Step, we will emit a reference to React/FunctionComponent# which doesn't make sense.

Originally posted by @varungandhi-src in #46 (comment)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions