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

Ambient const enums are not allowed when the '--isolatedModules' flag is provided (with typescript) #4538

Closed
steabert opened this issue Feb 7, 2019 · 7 comments

Comments

@steabert
Copy link

steabert commented Feb 7, 2019

Bug Report

Current Behavior
When compiling a typescript file that imports something from rxjs with the isolatedModules option for typescript set to true, the following error occurs:

node_modules/rxjs/internal/Notification.d.ts:3:27 - error TS1209: Ambient const enums are not allowed when the '--isolatedModules' flag is provided.

3 export declare const enum NotificationKind {

Reproduction

Create minimal project

yarn add --dev typescript rxjs
ts 

Create test.ts:

import {Observable} from 'rxjs'

Run Typescript compiler

yarn tsc --lib esnext --isolatedModules test.ts

Expected behavior
No error.

Environment

  • Runtime: Node v10.15.0
  • RxJS version: 6.4.0
  • (If bug is related) Loader, build configuration: typescript 3.3.1

Possible Solution

Additional context/Screenshots
Add any other context about the problem here. If applicable, add screenshots to help explain.

@cartant
Copy link
Collaborator

cartant commented Feb 7, 2019

I'm not familiar with the error, but I have a hunch that it might be addressed by the enum being exported in this PR: #4514

@BrianMitchL
Copy link

BrianMitchL commented Feb 7, 2019

This also causes compilation errors with @babel/plugin-transform-typescript (the TypeScript compiler used in create-react-app), which does not support const enums.

EDIT: I've created issue #4555 to track this separately.

@cartant
Copy link
Collaborator

cartant commented Feb 8, 2019

@BrianMitchL Although it also pertains to const enums, your issue is unrelated to this one. Please open an issue and fill out the template - including all relevant version information.

IIRC, TypeScript 2.4 is the version in which const enums were introduced, so I'd be more than a little surprised if the current version of the transform does not support them.

Anyway, please move all discussion to a new issue.

@am17torres
Copy link

am17torres commented Feb 9, 2019

@steabert I just ran into this issue after running a yarn upgrade

./node_modules/rxjs/internal/Notification.d.ts
Type error: Ambient const enums are not allowed when the '--isolatedModules' flag is provided.  TS1209

    1 | import { PartialObserver } from './types';
    2 | import { Observable } from './Observable';
  > 3 | export declare const enum NotificationKind {
      |                           ^
    4 |     NEXT = "N",
    5 |     ERROR = "E",
    6 |     COMPLETE = "C"

Downgrading rxjs from 6.4.0 to 6.3.3 removed that error.
This looks like the problem line

@cartant - I think you can simply export * from './internal/Notification';

I'm not sure if this is helpful 🤷‍♂️
DefinitelyTyped/DefinitelyTyped#28744 (comment)
https://github.com/DefinitelyTyped/DefinitelyTyped/pull/29783/files#diff-ec9dabea74600f252c17af9dbe837891R30

One last thought, I'm not too sure if you need to export const enum vs export enum. There is a pretty in-depth explanation on stack overflow

@cartant
Copy link
Collaborator

cartant commented Feb 11, 2019

@am17torres Yeah, exporting won't solve this. See this comment.

@mrmckeb
Copy link

mrmckeb commented Feb 11, 2019

We're facing this issue too, and I think it's going to affect a lot of people sadly.

Any ideas for workarounds? For now we're forcing the last release (using Yarn's resolutions).

Would the quick fix be to remove const?

@cartant
Copy link
Collaborator

cartant commented Feb 11, 2019

@mrmckeb I think pinning your resolution to 6.3.3 would be the quickest, simplest solution, for now.

cartant added a commit to cartant/rxjs that referenced this issue Feb 11, 2019
cartant added a commit to cartant/rxjs that referenced this issue Mar 26, 2019
BioPhoton pushed a commit to BioPhoton/rxjs that referenced this issue May 15, 2019
* fix(Notification): replace const enum

Closes ReactiveX#4538

* chore: use literal union and keep enum

The enum is kept, but it is no longer a const enum. It cannot be exported as a const enum without effecting an error if isolated modules are used.
@lock lock bot locked as resolved and limited conversation to collaborators May 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants