DexTer
DexTer

Reputation: 2103

Can TypeScript be used with existing JavaScript code?

I am working on pretty big existing web application with team. Time to time we experience common JavaScript coding nuances like case difference while function calling or missing operator etc.

I find TypeScript promising solution for such issues specially while working with team on different files/modules. It has many benefits like

I know there are converters available which can convert JavaScript to typescript but I do not want to convert existing project files to TypeScript.

I was wondering if it is possible to keep existing code as is and develop new modules/files in TypeScript. May be we can migrate existing files in gradual manner.

Will they work well together? How to do it?

I have tried to read online but couldn't find much relevant information other than converting existing projects to TypeScript.

Upvotes: 2

Views: 433

Answers (1)

Andreas Frische
Andreas Frische

Reputation: 9891

Yes. From the language spec :

TypeScript is a syntactic sugar for JavaScript. TypeScript syntax is a superset of ECMAScript 6 (ES6) syntax.

Every JavaScript program is also a TypeScript program. The TypeScript compiler performs only file-local transformations on TypeScript programs and does not re-order variables declared in TypeScript. This leads to JavaScript output that closely matches the TypeScript input. TypeScript does not transform variable names, making tractable the direct debugging of emitted JavaScript. TypeScript optionally provides source maps, enabling source-level debugging. TypeScript tools typically emit JavaScript upon file save, preserving the test, edit, refresh cycle commonly used in JavaScript development.

Upvotes: 2

Related Questions