Hacker Newsnew | past | comments | ask | show | jobs | submit | Tx3's commentslogin

Hey, I just tried to be polite.. but yes, you're absolutely right, understatement of the century!


Interesting solution, thank you for the link!


In the blog post, I have one example of the React use case with screen capture.

I find it very helpful to have properties defined, so when I use the component, I immediately know what are the props I can provide.

There are some 3rd party React components that won't have type definitions yet, but the popular ones are well covered. I have written most of the components I have used, so I haven't had many problems.


Rob is exactly right that you should use --outDir

You should aim for deployment process where outDir would be in .gitignore and building of the JS files would happen on a build server.


If you use --outDir, wouldn't the .js files that import the transpiled .ts files need to point to outDir instead?

This is the kind of stuff that makes the "incremental" adoption argument hard for me to swallow. If I can't rewrite a .js file to .ts without any further ripple effects within the project, then it's not truly incremental.

I wrestled with this stuff last week and ultimately ended up going with flow since it gave me type checking _and_ incremental adoption, without complicating my existing babel/webpack stack.


Hey, I work on the TypeScript team. I hope you'll reconsider, and maybe you can fill me in on the issues you ran into.

Your .js files should typically be relative to each other, so unless you're using absolute paths (which you usually shouldn't!), this hasn't been a problem for other users. Is there something that I'm missing?


Hey Dan, thanks for responding. I think the key point you may be missing (or perhaps I missed a flag somewhere) is that I want relative requires but I don't want the intermediate js and sourcemap files cluttering up my project (and assuming I have an existing babel/webpack stack I'm happy with -- I just want the type checking).

I want the ability to convert any existing js file within the project to ts without having to touch a single other source file. I also want the type checker to assume that if I don't have a type definition for a package, that I don't want the use of that package to be type checked (without being forced to rewrite my ES6 imports to commonjs).

I was able to do this with flow but not typescript.

Is there something I'm missing?


Hey rhymohr, I think I see what you mean. If you're already using something like Babel & Webpack, it should just be a matter of using a TypeScript loader like ts-loader[1] or awesome-typescript-loader[2]. TypeScript should just fit into that build step.

Let me know how that ends up working out!

[1]: https://github.com/TypeStrong/ts-loader [2]: https://github.com/s-panferov/awesome-typescript-loader


The .js files don't import the transpiled .ts files -- the .ts files are written to import other .ts files using relative paths.

A.ts importing B.ts would be `import * as A from "./B"`, where the transpiled A.js file would import from `./B.js` rather than the original A.ts file.

Furthermore you can mix JS into your compilation process and the TS compiler will* accommodate you by compiling your JS alongside your TS code.[1]

* TypeScript 1.8

[1] https://github.com/Microsoft/TypeScript/issues/4792


Good point! I used similar categorising as Anders Hejlberg used in the JavaScript Jabber podcast (https://devchat.tv/js-jabber/209-jsj-typescript-with-anders-...). For those who don't like audio, he basically referred TypeScript being superset of JavaScript, unlike some other languages.


Somehow I can't stand listening to Hejlberg.

Often it feels like the CS professors I met at university, who wanted to teach you about "real programming languages and not such toys like JavaScript"


I can't go with that. Anders H is one of the most avuncular, helpful and accessible voices out there. Oh and his very verbs twinkle!


Well, I just saw a talk about TypeScript 2 and it felt to me that he was belittling JavaScript.


JS is very cool because of how readily available it is and the awesome ecosystem that has grown around it. That said - you don't have to be a CS professor to see that the language (especially in early incarnations) wasn't well designed, to put it nicely. A.H. knows this just like anyone with the skills to design languages and compilers.


If you've ever worked with a strongly typed language you can't but belittle JavaScript ;)


I worked with C++, Java and Scala, and all felt really unwieldy.


You may be traumatised if you ever hear Crockford talk about JavaScript!


Haha, I met him on a JS conf once. There was one of those old "JavaScript has no types and is no real language" guys and he kicked his ass.

Basically he said static typing could be good and there were languages like Scala out there with real good type systems, but most of the "pro static types"-fanboys are using crap like Java or C++.


You're not your programming language. When people are expressing distaste about a language, it's (usually) not an attack towards its users.


Yes, but talking about "toy languages" when literally millions of people on the world make a living out of this is just mean :(


It also depends on how deep do you want to go with language features.

Let's say you have existing ES2015 source code. You could start experimenting on a local machine and use a script to rename js files to ts. Run the TypeScript compiler and annotate some of the most used functions.

You can then check what is the experience of using those functions that have type annotations, what is the speed of the development, etc.

Sit down with colleagues, show what you have done and ask what do they think. You can then decide to proceed and stick with type annotations until you're sure. Use boy scouts rule: "Always leave the campground cleaner than you found it." aka add typings to the function declaration.


About pre-existing libraries that don't have type definitions.

The way I dealt (until proper type definitions are written) was:

declare module "react-loader" { var noTypeInfoYet: any; export = noTypeInfoYet; }


I wonder is it some black humour to choose padLeft as an example source code. :)

Thanks for the links, future looks promising indeed.


About the text editor: I think all editors use the same TypeScript compiler APIs. That would mean that you would get pretty much same suggestions, error lists, etc. Correct me if I am wrong. VS Code could have some other API calls or project file support.

JS Jabber episode was great! Full of great insights.


I use TypeScript from both Emacs and VSCode, depending on my mood. They do both use the same underlying compiler API, but the VSCode support is more pleasant in how it's surfaced in the editor: ctl-click on a variable to jump to its definition, f2 to rename the variable under the cursor, or ctl-T to open a query field to jump to a symbol.

Emacs is capable of all of these things (because Emacs is capable of anything) but it doesn't work that way out of the box nor is there an already-written package around that makes that easy. To rename you type M-x tide-rename-symbol and it's inconvenient enough that I forget to use it.


So bind f2 to tide-rename-symbol in the mode map.

And throw the bind into your .emacs


It would be interesting to hear more about your experiences. I have been quite hesitant to use more advanced TypeScript features and stayed on a type system related annotations.


Interestingly enough, the Typescript compiler team doesn't even use classes. If you want, you pretty much write just functional code.


Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: