From 4183cdcde3499113dda18908602864aee63e293d Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Thu, 21 Mar 2019 16:50:26 +0000 Subject: [PATCH] docs: show how you can get the types to work in a `commonjs` module --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ee1e39278a5..55f77140605 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ web3.eth.getAccounts() ### Usage with TypeScript -We do support types within the repo itself. Please open an issue here if you find any wrong types. +We support types within the repo itself. Please open an issue here if you find any wrong types. You can use `web3.js` as follows: @@ -74,6 +74,15 @@ import Web3 from 'web3'; const web3 = new Web3("ws://localhost:8546"); ``` +If you are using the types in a `commonjs` module like for example a node app you just have to enable `esModuleInterop` in your `tsconfig` compile option, also enable `allowSyntheticDefaultImports` for typesystem compatibility: + +```js +"compilerOptions": { + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + .... +``` + ## Documentation Documentation can be found at [read the docs][docs]