fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

Ambient const enums are not allowed when the '--isolatedModules' flag is provided

Open gsbelarus opened this issue 8 years ago • 24 comments

Project created with create-react-app 2.1 with TS 3.1.6 is not compiling and falling with error:

yarn build

yarn run v1.12.3 $ react-scripts build Creating an optimized production build... Failed to compile.

.../node_modules/@uifabric/utilities/lib/KeyCodes.d.ts Type error: Ambient const enums are not allowed when the '--isolatedModules' flag is provided. TS1209

4 |  * @public
5 |  */

6 | export declare const enum KeyCodes { | ^ 7 | backspace = 8, 8 | tab = 9, 9 | enter = 13,

Project dependencies:

  "dependencies": {
    "@types/dagre": "^0.7.40",
    "@types/jest": "^23.3.9",
    "@types/node": "^10.12.5",
    "@types/react": "^16.7.3",
    "@types/react-dom": "^16.0.9",
    "dagre": "^0.8.2",
    "office-ui-fabric-react": "^6.102.0",
    "react": "^16.6.1",
    "react-dom": "^16.6.1",
    "react-redux": "^5.1.1",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.1.1",
    "redux": "^4.0.1",
    "redux-devtools-extension": "^2.13.5",
    "redux-thunk": "^2.3.0",
    "typesafe-actions": "^2.0.4",
    "typescript": "^3.1.6"
  },

gsbelarus avatar Nov 15 '18 09:11 gsbelarus

We're actually in the middle of addressing this issue. Half of it landed last night: https://github.com/OfficeDev/office-ui-fabric-react/commit/a995de20dcd7b3a8967e6d33ccffd6f12dae0ed5

I'm working on the icon names and const enums across more packages now.

kenotron avatar Nov 15 '18 20:11 kenotron

If you feel that this is resolved, please feel free to close this. We're taking an approach of carefully moving over to something other than const enum trying to figure out the implications of size differences in the package before and after. It'll likely take a few more days to completely land.

kenotron avatar Nov 15 '18 21:11 kenotron

I'm hitting this right now, should this be re-opened?

cschleiden avatar Nov 19 '18 05:11 cschleiden

If you are on latest version and there are still global exported enums, than definitely should be.

PS: until they are cooperating with TS guys to address this problem on TS behalf.

gsbelarus avatar Nov 19 '18 05:11 gsbelarus

@kenotron I'm hitting this with the latest packages right now because of the icon names. You mentioned that you'd fixed part 1 of 2 so if there is another issue tracking part 2 please feel free to resolve as dupe.

cschleiden avatar Nov 19 '18 15:11 cschleiden

Hey @cschleiden - yeah we haven't finished the work yet, though you can track it here: #7119

kenotron avatar Nov 19 '18 16:11 kenotron

Hi is there any progress on the matter? still same behavior. Seems to be critical as it totally blocks using the fabricui in react+typescript app

dushes-ag avatar Dec 10 '18 13:12 dushes-ag

@dushes-ag : @kenotron and I will be tackling the matter of IconNames as that should be the last outstanding const enum in the library, but it's a little trickier to handle because of the devexp of using IconNames right now.

That said, in the meantime, const enum should not block use of Fabric in React + TypeScript apps generally. It is because Create React App's baked-in TypeScript support uses Babel, which doesn't support const enum. So if you use another method of creating a React app you shouldn't be blocked.

One way around this that lets you still use CRA is to use react-scripts-ts (we use this on the Getting Started page):

npx create-react-app my-app --scripts-version=react-scripts-ts

Jahnp avatar Dec 12 '18 00:12 Jahnp

@Jahnp is there any other known work around since react-scripts-ts is deprecated?

drewloomer avatar Dec 13 '18 01:12 drewloomer

@drewloomer oh shoot, I didn't realize that was the case. I'm not aware of another work around right now. We'll have to get back to you on that.

There's a decent chance we'll be removing the const enum from IconNames over the next few weeks altogether, so the matter should sort itself out soon.

Jahnp avatar Dec 13 '18 01:12 Jahnp

@drewloomer What I'm doing as a work around is going to the IconNames.d.ts file within node_modules and I'm simply removing the const from the enum. This should suffice for development purposes until the team fully deprecates this last const enum.

BTC-Bradley avatar Dec 17 '18 22:12 BTC-Bradley

I was able to suppress this without making code changes to prepackaged code by setting "skipLibCheck": true" in my tsconfig.json

chriskuech avatar Dec 18 '18 01:12 chriskuech

@Jahnp It looks like the only const enum issue left is the icons, correct? Can we open up an issue specifically for icons and close this one up?

micahgodbolt avatar Dec 28 '18 23:12 micahgodbolt

Any updates on this issue?

SudharsanSukumar avatar Jan 23 '19 00:01 SudharsanSukumar

@BTC-Bradley - after a lot of thinking on this issue, we're gonna deprecate the IconNames module. Most of consumers are using <Icon> with a plain string name that is taken from the tool:

https://uifabricicons.azurewebsites.net/?help

It's not the resolution you probably want, but in a rare occasion I'm actually recommending against having a real type here so far. We can probably do better in a later major rev of Fabric where we could export little constants (e.g. export const FooIconName='FooIcon'). The #8003 issue should be addressed by adding a @deprecated flag in IconNames.

kenotron avatar Feb 14 '19 21:02 kenotron

Ooops, just saw @JasonGore marking the newer bug resolved. I'm gonna keep this one open for the @deprecated work

kenotron avatar Feb 14 '19 21:02 kenotron

:tada:This issue was addressed in #8005, which has now been successfully released as @uifabric/[email protected].:tada:

Handy links:

msft-github-bot avatar Feb 18 '19 13:02 msft-github-bot

:tada:This issue was addressed in #8005, which has now been successfully released as [email protected].:tada:

Handy links:

msft-github-bot avatar Feb 18 '19 13:02 msft-github-bot

Thanks @kenotron for the quick response!

BTC-Bradley avatar Feb 19 '19 23:02 BTC-Bradley

@kenotron, would it also be possible to remove the const from the enum since it's deprecated? This would resolve the error for this issue until the enum is completely removed.

enum

BTC-Bradley avatar Feb 20 '19 00:02 BTC-Bradley