Let's see your example buddy?
It can be fixed via babel-plugin-module-resolver, though. Actually, Babel can do much more than tsc, and typescript can run under it as well.
Only just it doesn't help with the IDE.
I have two files:
src/index.ts
import { add } from 'utils/math' console.log(add(2, 3))
src/utils/math.ts
export const add = (a, b) => a + b
My tsconfig.json - the rest is omitted
{ "baseUrl": "./src", "paths": { "*": ["*"] } }
After transpiling this to JS, it doesn't work just by calling node dist/index.js, where dist is the output folder. So the baseUrl is just for TypeScript as Node doesn't understand that.
node dist/index.js
baseUrl
Now I really need to compile to JavaScript as you mentioned.
I summed up the solution, but not exactly that pretty.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Let's see your example buddy?
It can be fixed via babel-plugin-module-resolver, though. Actually, Babel can do much more than tsc, and typescript can run under it as well.
Only just it doesn't help with the IDE.
I have two files:
src/index.ts
src/utils/math.ts
My tsconfig.json - the rest is omitted
After transpiling this to JS, it doesn't work just by calling
node dist/index.js
, where dist is the output folder. So thebaseUrl
is just for TypeScript as Node doesn't understand that.Now I really need to compile to JavaScript as you mentioned.
I summed up the solution, but not exactly that pretty.
TypeScript, simplified import paths, and what you have to be careful
Pacharapol Withayasakpunt ・ Jul 23 ・ 2 min read