Skip to content

Naming conflict ends up in unhandled compiler error #38532

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

Closed
timsuchanek opened this issue May 13, 2020 · 0 comments · Fixed by #39053
Closed

Naming conflict ends up in unhandled compiler error #38532

timsuchanek opened this issue May 13, 2020 · 0 comments · Fixed by #39053
Assignees
Labels
Bug A bug in TypeScript

Comments

@timsuchanek
Copy link
Contributor

TypeScript Version: 3.7.x-dev.201xxxxx

Search Terms:

Code
It seems, that the combination of importing Debug, redefining it as a function and then setting a property on that function (Debug.enable) breaks the compiler.

import Debug from 'debug'

const cache: any[] = []

const MAX_LOGS = 100

const namespaces: string[] = []

// for our use-case, map is faster, as retrieving values is faster than with Set or Object
const enabledNamespaces: Map<string, true> = new Map<string, true>()

export default function Debug(namespace: string): Debug.Debugger {
  const debug: any = Debug(namespace)
  namespaces.push(namespace)

  Debug.enable(namespaces.join(','))

  debug.log = (...args) => {
    cache.push(args)
    // keeping 100 logs is just a heuristic. The real truncating comes later
    if (cache.length > MAX_LOGS) {
      cache.shift()
    }
    if (enabledNamespaces.has(namespace)) {
      console.error(...args)
    }
  }

  return debug
}

Debug.enable = (namespace) => {
  enabledNamespaces.set(namespace, true)
}

Expected behavior: The compiler should give me a readable error message, that I have a naming conflict.

Actual behavior:

errors.ts:22 Uncaught Error: Cannot read property 'kind' of undefined

TypeError: Cannot read property 'kind' of undefined
    at Object.e.isFunctionDeclaration (tsWorker.js:21)
    at Object.$n [as getEffectiveTypeAnnotationNode] (tsWorker.js:21)
    at tsWorker.js:21
    at Vm (tsWorker.js:21)
    at Qm (tsWorker.js:21)
    at Jm (tsWorker.js:21)
    at a_ (tsWorker.js:21)
    at tsWorker.js:21
    at Gy (tsWorker.js:21)
    at tsWorker.js:21
    at errors.ts:22

Playground Link

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jun 6, 2020
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.0 milestone Jun 6, 2020
elibarzilay added a commit to elibarzilay/TypeScript that referenced this issue Jun 12, 2020
Test that `parentSymbol.valueDeclaration` exists.

Fixes microsoft#38532
elibarzilay added a commit that referenced this issue Jun 13, 2020
Test that `parentSymbol.valueDeclaration` exists.

Fixes #38532
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants