This feature is to support vanilla js code in typescript for popular libs like jquery, loadash, etc.
How to use ?
Declaration files (
As an example, getting the declarations for a library like lodash will be just an npm command away:
npm install --save @types/lodash // or npm install -S @types/foo-bar
From there you’ll be able to use lodash in your TypeScript code with no fuss. This works for both modules and global code.
For example, once you’ve
npm install-ed your type declarations, then you can use imports and write
import * as _ from "lodash"; _.padStart("Hello TypeScript!", 20, " ");
or if you’re not using modules, you can just use the global variable
_ if you have a
_.padStart("Hello TypeScript!", 20, " ");
Looking for more than just lodash? Well, we’re also making it extremely easy to figure out which packages have the type declarations you need. We now have a type search at https://aka.ms/types where you can find the package for your favorite library.
Best of all, this all works today with our nightly builds. Just run
npm install -g typescript@next, and give it a shot. This is all you need to know to start experiencing the future of type acquisition.