Fixing Typescript error: TS2666: Exports and export assignments are not permitted in module augmentations

When I set up typings to run with typescript, I got stuck for a while trying to get imports from external libraries to work, with this error:

typings/main/definitions/react/index.d.ts(2322,5): error TS2666: Exports and export assignments are not permitted in module augmentations.

This happens, for instance, trying to use React:

import * as React from 'react';

interface IMessage {
  msg: String;
}

class TestApp extends React.Component {
  public render(): Element {
    return 
test
; } }

The reason for this is you need use a special incantation to install libraries:

typings install react --ambient --save

In order for this to work without weird reference comments in the file, you also need a tsconfig.json:

{
    "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "jsx": "react",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "outDir": "dist"
    },
    "exclude": [
        "node_modules",
    "dist",
    "node_modules",
    "typings"
    ],
    "files": [
      "./app/index.tsx",
      "./typings/main.d.ts"
    ]
}

Leave a Reply

Your email address will not be published. Required fields are marked *