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

Cannot use enum from project A from project B even if the function used in B is imported from A #5382

Closed
kenotron opened this issue Oct 23, 2015 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@kenotron
Copy link
Member

Error message says:

error TS2345: Argument of type 'Foo' is not assignable to parameter of type 'Foo'.

Given the exact same exported type, Typescript isn't able to deal with enums from multiple source locations. Here's an example with a Core project and a Bar project:

Core/
  foo.ts
  convertFooToString.ts
  dist/
    foo.js
    foo.d.ts
    convertFooToString.ts
    convertFooToString.d.ts

Bar/
  SomeComponent.tsx
  dist/
    SomeComponent.js
    SomeComponent.d.ts

SomeComponent.tsx:

// some other imports
import {convertFooToString}
export default class SomeComponent extends React.Component<any, any> {
  render() {
    // Note, this.props.foo IS a Foo type
    return (<div>{convertFooToString(this.props.foo)}</div>);
  }
}

foo.ts:

enum Foo {
  Yay = 0,
  Nay = 1
};

export default Foo;

convertFooToString:

export function convertFooToString(foo: Foo): string {
    switch (foo) {
        case Foo.Yay:
            return "YAYAYAYAYA";
        default:
            return "NANANANANA";
    }
}
@mhegazy
Copy link
Contributor

mhegazy commented Oct 23, 2015

it is not clear what is going on from your description, i do not know where the error is reported, and where hte import is coming from etc.. but this looks like a duplicate of #4800..

@mhegazy mhegazy added the Duplicate An existing issue was already created label Oct 23, 2015
@xogeny
Copy link

xogeny commented Dec 31, 2015

This issue was long ago marked as a duplicate. Shouldn't it be closed (especially since the issue it is supposedly a duplicate of, #4800, is actually closed)?

@mhegazy mhegazy closed this as completed Jan 4, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants