typescript-strictly-typed

Enable configurations for strictly typed TypeScript, ESLint or TSLint, and optionally Angular. Because TypeScript strict mode is not enough.

Usage no npm install needed!

<script type="module">
  import typescriptStrictlyTyped from 'https://cdn.skypack.dev/typescript-strictly-typed';
</script>

README

TypeScript Strictly Typed

Enable configurations for strictly typed TypeScript, ESLint or TSLint, and optionally Angular. Because TypeScript strict mode is not enough.

A blog post explains the motivation of this lib.

Warning

Going fully strict is a choice to make at the very beginning of a project.

Enabling all strict options at once in an existing project is strongly discouraged, as hundred of errors would appear. Converting an existing project to full strict mode is still possible, but it should be done incrementally, by activating each option one by one.

On the other hand, it's recommended to redo the command when doing major updates of your tools (TypeScript, ESLint or Angular) to add newly introduced strict options, to stay up to date with best practices.

Getting started

Check the Git (or equivalent) status is clean, to be able to revert easily if needed, then just run the following commands in your terminal:

cd path/to/my-project
npx typescript-strictly-typed

npx is a command included in Node/npm. In case of problem (there is a known issue with npx on Windows if your user path contains a space, like C:\Users\Hello World), just do the full commands:

cd path/to/my-project
npm install typescript-strictly-typed -g
typescript-strictly-typed

What does it do?

Adding configuration for:

Sponsorship

Except this library, my open source work includes the Angular async local storage lib, downloaded more than 15 000 times each week, and the Angular schematics extension for VS Code, used by 500 000 users. It represents months of full time unpaid work.

So please consider to sponsor (or ask your company to do so). In addition to support open source, it will grant you access to the Schematics Pro sponsorware, which helps you build optimized and architectured Angular projects in no time.

Requirements

Node & npm

You need a LTS version of Node and npm, ie. currently:

  • Node >= 12.13
  • npm >= 6.12

Directory

Be sure to invoke the command in the root directory of your project, ie. where your configuration files (like tsconfig.json) are located.

TypeScript

strict mode is available in TypeScript >= 2.3.

ESLint

ESLint must be configured for TypeScript, ie. with:

  • "parser": "@typescript-eslint/parser" and "plugins": ["@typescript-eslint"]
  • or an equivalent (for example Vue uses "extends": ["@vue/typescript"] and React uses "extends": "react-app")

Official getting started documentation of @typescript-eslint

Angular

The project must use a LTS version of Angular CLI, ie. with a angular.json file.

Known limitations

This lib is here to promote good practices. But at the end of the day, it just adds a few lines in configuration files, as explained above in "What does it do?".

It was already a lot of work to support all possible official configuration formats. So if it doesn't work for your project because of a custom configuration, you can just modify the configuration files yourself.

Apps using .eslintrc.js (including Vue)

If your project uses a .eslintrc.js file (instead of a more classic .eslintrc.json file) you'll have to copy the strict rules newly generated in .eslintrc.json file into the existing .eslintrc.js file.

For Vue apps created with vue create, after running this lib command, it will work out of the box if you chose one of the following Vue options:

  • ESLint with config stored in package.json
  • TSLint

But if you chose ESLint with a dedicated config file, Vue will create a .eslintrc.js file and so you'll have to do the above step.

See issue #3 if you want to help.

Changelog

Changelog available here.

License

MIT