4 ms·
The TypeScript compiler is the canonical corpus of code written by TypeScript experts, and I learned a lot of interesting style from the time I've spent with it
by evmar 9y ago
The TypeScript compiler is the canonical corpus of code written by TypeScript experts, and I learned a lot of interesting style from the time I've spent with it. (Fun fact: they don't use 'class' in the compiler at all, but instead have a different pattern for passing around interfaces+state that is much more TypeScript-y.)
- Scarbutt 9y agoFun fact: they don't use 'class' in the compiler at all Looks like a class to me: https://github.com/Microsoft/TypeScript/blob/master/src/compiler/core.ts#L79 https://github.com/Microsoft/TypeScript/blob/master/src/comp...
- nblavoie 9y agoWhat strikes me first is the comment above the function : // Keep the class inside a function so it doesn't get compiled if it's not used. I didn't know it was possible.
- deleted 9y ago[deleted]
- wwwigham 9y agoWe do use classes in the test harness, services layer, and to polyfill es6 Map. We just don't use them in the design of any compiler subsystems.
- chamakits 9y agoThis is very interesting to me. Is the reasoning behind this documented anywhere? I could only find instructions the coding guideline indicating as much (here: https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines#classes https://github.com/Microsoft/TypeScript/wiki/Coding-guidelin...) but couldn't find why. I'd love to know why, may better inform my usage of typescript.
- roadtestman 9y agobring a horse to water ... but cant make it drink you have all the answers in front of you do you need them to read the code for you? Come on man. A little effort please. Its not like you have been neglected with info.
- vdnkh 9y agoFor better or worse? I've avoided classes in our codebase because I don't like the lack of privates via closure (revealing module pattern) and it's transpiler overhead, but it's a very powerful organization tool. I've found code to be much neater in the class format.
- sillysaurus3 9y agoLooks like C++ circa 2008. Careful with those abstractions. That seems a stone's throw away from template metaprogramming.
- zengid 9y agoCould you cite an example of the interfaces+state pattern? You've piqued my interest.
- HumanDrivenDev 9y agoSeconded, I'm also very interested.
- bulldoa 9y agodoes anyone have some recommendation on how to debug typescript compiler, it seems like console does not work there, I am trying to just step through tsc.ts, but gulp local always complains that console is not defined. Is there any alternative in stepping through the compiler?
- olingern 9y agoIt looks like there is a lot of legacy code hanging out in the compiler [1], i.e. prefer module over namespaces. [1] - https://github.com/Microsoft/TypeScript/blob/master/src/compiler/watch.ts https://github.com/Microsoft/TypeScript/blob/master/src/comp... It's also strange to me why they inline their interfaces, rather than organizing them in a common folder / module.