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

exported Enum resolution error #570

Closed
christyharagan opened this issue Sep 14, 2015 · 4 comments
Closed

exported Enum resolution error #570

christyharagan opened this issue Sep 14, 2015 · 4 comments

Comments

@christyharagan
Copy link

Hey,

I think this is an atom-typescript error as I've tried compiling this from typescript@next directly, and it seems to compile fine.

The error relates to enums, and exports using the new typescript node resolution (with the typings property in the package.json).

The bug can be reproduced through the following scenario: (Sadly I can't attach a .zip, so ask me if you want the contents directly for easy import and analysis):

Three projects: a, b, c.

b depends on a
c depends on b

a exports an enum through its index.ts:

export enum E{}

b then exports a function that returns E through its index.ts:

import {E} from 'a'
export function f():E {
  return null
}

c then consumes f through its index.ts:

import {E} from 'a'
import {f} from 'b'

let e:E = f()

There is now an error for e:

Type 'E' is not assignable to type 'E'.

All three packages have a package.json that looks like this:

{
  "name": "b",
  "version": "1",
  "main": "lib/index.js",
  "typings": "lib/index.d.ts",
  "dependencies": {
    "a": "1"
  }
}

And a tsconfig.json that looks like:

{
    "compilerOptions": {
        "declaration": true,
        "module": "commonjs",
        "rootDir": "./src",
        "target": "es5",
        "outDir": "./lib"
    },
    "files": [
        "src/index.ts"
    ]
}

Now, what's especially interesting, is if you have the rootDir and outDir the same, then the error doesn't occur.

Furthermore, this defect occurs if f were to export another symbol (e.g. an interface) which references an exported enum somewhere within it's structure or hierarchy (which was how I encountered this bug, and it took me some time to track it down to this specific scenario)

This only seems to affect enums, not other types.

@basarat
Copy link
Member

basarat commented Sep 14, 2015

so ask me if you want the contents directly for easy import and analysis

Please. As creating three projects and then setting them up to fail can be a major time drain. You can upload them to a new random github repo 🌹

@christyharagan
Copy link
Author

Hey Basarat,

Of course :) here you go:

https://github.com/christyharagan/typeScript-enum-export-bug

For clarity, if you open the file:

c/index.ts

then you'll find the error on line 3.

@christyharagan
Copy link
Author

Duh I'm an idiot. Realised this is a TypeScript bug, not an atom-typescript one. Closing this down, as I've raised microsoft/TypeScript#4800

@basarat
Copy link
Member

basarat commented Sep 15, 2015

No worries. Thanks for being a cutting edge and patient user as we keep experimenting 🌹

@TypeStrong TypeStrong locked and limited conversation to collaborators Jan 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants