freddy freddy - 4 months ago 67
TypeScript Question

TypeScript - how to exclude one of the typings?

I'm creating a web + mobile app using react-native and TypeScript. So essentialy, I have two different outputs for two different TS configs.

For the web, my target is

es5
and module
commonjs
. So I have to use the
es6-shim
typing to make
tsc
happy when transpiling.

For mobile (different
tsconfig.json
), my target is
es6
and module
es6
. The problem is that this collides with the
es6-shim
typing and
tsc
outputs many "Duplicate identifier" errors. If I remove the shim,
tsc
is happy (but then web transpilation stops working).

I've tried excluding the typing in the tsconfig for mobile like so:

...
"exclude": [
"typings/globals/es6-shim",
...


...but no luck, TypeScript compiler finds the typing anyway (probably because of a reference from
typings/index.d.ts
to the es6-shim typing) and still outputs many "Duplicate identifier" errors for the mobile build.

Am I doing the ignore the wrong way? Am I thinking about it wrong and there is some other way to solve this?

Answer

Exclude typings/index.d.ts for the ES6 build as well.

If you have something else in that file that needs to be included in the ES6 build, then move out es6-shim reference into a separate .d.ts file for the ES6 build and exclude that instead.