Pregunta

I'm starting a personal web project and I would like to use the new TypeScript release to build JS part.

I'm wondering what would be the best architecture to build one: usually, I like having one class per file. Here, with what I read from official doc, it would be hard to match this pattern (with reference tags or import keyword)...

I would like to know your tricks to avoid long dependency edits each time you're refactoring something.

I know it's possible to compile your whole project in a single file but, for my part, I don't like this for performances (and you're still using reference tags). I prefer using requireJS but with TS, you're using relative paths and strings to import your classes, what annoy me a bit ^^

Feel free to give me some advices :) I'll appreciate your help!

¿Fue útil?

Solución

I haven't documented it perfectly but grunt-ts can help you with the multiple import problem (https://github.com/grunt-ts/grunt-ts/issues/85#issue-29515541).

What you do is type in ///ts:import=filename and grunt-ts keeps the generated import statement in sync as you refactor your project.

You can also load entire folders using the same syntax i.e. ///ts:import=foldername and even generate an index.ts for a folder using the same syntax and them import that index.ts instead of importing the folder everytime.

To get started with grunt-ts just follow the readme : https://github.com/grunt-ts/grunt-ts#grunt-ts

Advantages :

  • faster to get started. Relative paths are hard to type
  • easier to refactor (as long as you keep the filenames the same). And when you do change the filenames .. you get compile errors.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top