Skip to content

Latest commit

 

History

History
31 lines (19 loc) · 5.38 KB

File metadata and controls

31 lines (19 loc) · 5.38 KB

TypeScript

Status of TypeScript in Liferay projects

We are trialing or using TypeScript in a number of projects. In order of adoption, these include:

For other projects, we should weigh up the relative costs and benefits of using TypeScript. For example, in projects that don't have build processes — examples include js-themes-toolkit and npm-tools — we've found that the ability to iterate and debug in-place (even inside the "node_modules") has been a useful debugging workflow that would be made more difficult if we switched to TypeScript, so we've stayed with untranspiled vanilla JavaScript so far.

Resources for learning TypeScript

For information about how TypeScript projects are configured and how the build works in Liferay DXP, see the documentation inside the @liferay/npm-scripts package.

To learn about TypeScript in general, the following resources may be useful:

Finally, exploring the bundled type definitions (example: DOM APIs) included with TypeScript itself can be a useful way to discover existing types that you can use in your own type annotations. In many cases, you can jump straight to these definitions by hitting the "go-to-definition" key-binding in your IDE or editor. Once configured, this "go-to-definition" trick will work for any type definitions that may be available from DefinitelyTyped; for example, if you look under modules/node_modules/@types in a liferay-portal checkout, you will see that we already have @types/react, @types/react-dom, and many others.

Guidelines and recommendations

We anticipate building up a set of lints and recommendations over time, as our usage of TypeScript grows. For now, we simply refer you to the TypeScript "Do's and Don'ts" page on the official TypeScript website. It contains some obvious best practices, such as strenuously avoiding the use of the any type and so on.

Additionally, we recommend the use of strict compiler settings wherever possible, to eliminate common sources of errors. As you can see, we have "strict": true set by default in the base TS configuration file that we use in Liferay DXP.