Last active
February 13, 2020 02:14
-
-
Save jkrems/f97d0e040f82c3c4120ca8d3f2fe2fff to your computer and use it in GitHub Desktop.
Node globals handling in Typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/node_modules | |
/input.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This should fail unless we target CommonJS. | |
// It could succeed when targeting CommonJS. | |
const s: string = __dirname; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "demo-node-globals", | |
"version": "0.0.0", | |
"lockfileVersion": 1, | |
"requires": true, | |
"dependencies": { | |
"@types/node": { | |
"version": "13.7.1", | |
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.1.tgz", | |
"integrity": "sha512-Zq8gcQGmn4txQEJeiXo/KiLpon8TzAl0kmKH4zdWctPj05nWwp1ClMdAVEloqrQKfaC48PNLdgN/aVaLqUrluA==" | |
}, | |
"typescript": { | |
"version": "3.7.5", | |
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz", | |
"integrity": "sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw==" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "demo-node-globals", | |
"version": "0.0.0", | |
"private": true, | |
"dependencies": { | |
"@types/node": "^13.7.1", | |
"typescript": "^3.7.5" | |
}, | |
"scripts": { | |
"test": "tsc --module CommonJS input.ts && !(tsc --module ESNext input.ts)" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"noEmit": true, | |
"module": "ESNext", | |
"types": ["node"] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment