Last active
January 9, 2023 16:12
-
-
Save rjmunro/428ec644b6e53a499ca3a5ba8de2edc7 to your computer and use it in GitHub Desktop.
Typescript weirdness
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
var a = require('./module1'); | |
var b = require('./module2'); | |
// import a from './module1'; | |
// import b from './module2'; | |
console.log('a',a); | |
console.log('b',b); |
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
let foo = 'hello1'; | |
module.exports = foo; |
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
let foo = 'hello2'; | |
module.exports = foo; |
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": "tstest", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"@types/node": "^7.0.0", | |
"typescript": "^2.1.5" | |
} | |
} |
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
{ | |
"compilerOptions": { | |
"outDir": "build" | |
}, | |
"exclude": [ | |
"node_modules", | |
"build" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
So the compiler throws an error but emits working code anyway.
If you comment out one of the
let foo = ..
lines, typescript's warnings go away, but the code it emits doesn't run. (I've commented line 1 of module2.ts below: