Reputation: 9103
I want to write a TypeScript library. I want to use 2.0 because, you know, it's the newest and it has a pretty cool set of features. However, I'm worried the majority of people (who probably still use 1.8-) won't be able to use it.
Are TypeScript 2.0 d.ts
definition files backwards compatible with version 1.8? If not, is there a set of best practices I can follow to ensure compatibility? Failing that, can I do anything else?
Upvotes: 1
Views: 497
Reputation: 220944
TypeScript 2.0 definition files are compatible with 1.8 as long as you don't expose any 2.0-specific features (such as readonly
or numeric literal types).
The simplest thing to do would be to develop as normal, and use an npm
-installed copy of the 1.8 compiler to validate that it's still able to parse the .d.ts file. Some other people in this situation have hooked in some Regexp replaces into their build chain to strip out a few 2.0-only features like readonly
from their .d.ts files.
In the future there might be a tool that downlevels 2.0-specific features into their nearest 1.8-compatible equivalents, but no one has written it yet (FWIW it'd be relatively simple).
never
typenull
and undefined
typesinterface I { x: 0 }
)this
types in function expressions and function types (e.g. f(this: something)
)export as namespace g
)readonly
Upvotes: 4