Edit: I meant refactoring as a way to improve the project, learn typescript, and learn the project itself inside and out.
Edit: I meant refactoring as a way to improve the project, learn typescript, and learn the project itself inside and out.
Javascript is Typescript. Typescript ⊇ Javascript.
Especially if you already use Babel (or any other JS preprocessor, like uglify or concat) and have a build pipeline ready, you can start using Typescript today.
Don't miss out!
PS: It will throw a lot of errors on a conventional codebase, but compile despite them. That's the point; install the compiler today, slowly start fixing the errors as you go. It's all about gradual improvement and optional typing.
You can (and always could) use almost any 3rd party lib with literally one line of code:
var somelib: any;
Done. No need to ever touch a .d.ts file.Sure, no type safety on the lib. But isn't that where we started, anyway?
This should be put on a giant banner on the TS homepage.
Thank you! How well would this work with an editor and typescript plugins? Say the amazing typescript-atom, I would guess the editor would crap its pants, no?
declare var somelib: any;
Done. Now the compiler and everything else will know that there's a global variable called `somelib` that does not have a specific type, and no matter how you use that variable, it's ok, you know what you're doing.Editors have no problem with it. They will simply see it as an "any" var. Completely compatible.
I wrote quite a bit of TS and this was how I used most obscure libraries. I can't be arsed to keep those stupid .d.ts files up to date and I trust the API docs. It's my own code I wanted to vet. Works like a charm.
Judicious use of declare var any, and ignoring compiler errors, is what really makes TS reality-compatible.
And for required modules, you'd need to shim require in similar fashion and use var instead of import.
declare function require(module: string): any;
var somelib = require("somelib"); declare module "somelib" {
var somelib: any
export = somelib
}You're not using the entire options parameter or https://github.com/flot/flot/blob/master/API.md ? Don't declare it - only add the properties you do use.
You're only using 3 methods from 1 class in aws-sdk ? Only declare that 1 class and 3 methods in your aws-sdk.d.ts