Type checking

Contents

Type checking is useful to catch errors early in the development process. This chapter will explain how to set up type checking for your project.

Configure

package.json

Add the following scripts to the package.json file:

{
  "scripts": {
    "check": "concurrently -c auto -g --timings npm:check:types",
    "check:types": "concurrently -g -r --timings npm:check:types:*",
    "check:types:assets": "node tsup/anyAssetFiles.js && npx tsc --noEmit -p src/main/resources/assets/tsconfig.json || exit 0",
    "check:types:server": "node tsup/anyServerFiles.js && npx tsc --noEmit -p src/main/resources/tsconfig.json || exit 0",
  }
}

build.gradle

Add the following task to the build.gradle file, which will run the npm check script defined in package.json:

build.gradle
tasks.register('npmCheck', NpmTask) {
	dependsOn npmInstall
	args = [
		'run',
		'check'
	]
	environment = [
		'FORCE_COLOR': 'true',
	]
}

check.dependsOn npmCheck

The last command makes sure that type checking is executed as a part of the build, but it can also be run separately (to skip the entire build process and just check for errors) with the following command:

./gradlew check

Summary

When building your app, it will now automatically perform type checking. In the next chapter we enable Linting of TypeScript code.


Contents

Contents