# Enabling TypeScript for a Component TypeScript checks front-end code as JavaScript. Writing code as TypeScript (`.ts`) in firefox-main is not supported, and not planned to be supported. You can enable it for a directory by adding a `tsconfig.json` file and adding the directory to the [TypeScript linter](../lint/linters/typescript.md). ## Steps 1. Add a `tsconfig.json` to the directory (see [The tsconfig.json File](#the-tsconfigjson-file)). 2. Check the directory, and exclude the modules that fail (see [Checking the Project](#checking-the-project)). 3. Register the directory with the linter and with CI (see [Registering with the Linter](#registering-with-the-linter)). ## The tsconfig.json File Start from this file, and adjust the `../../../` prefixes to the depth of your directory: ```json { "include": ["*.sys.mjs", "types/*.ts"], "exclude": ["SomeModule.sys.mjs"], "extends": "../../../tools/@types/tsconfig.json", "compilerOptions": { "checkJs": true, "strict": true, "noImplicitAny": false, "strictNullChecks": false, "plugins": [ { "transform": "../../../tools/ts/plugins/checkRootOnly.js", "transformProgram": true } ] } } ``` `extends` points to {searchfox}`tools/@types/tsconfig.json`. The file provides various set-up functionality to map module URLs to their sources and to provide the Gecko DOM and XPCOM types. It is suggested to keep the four compiler options as they are. Most projects currently in the tree set them. Turning `noImplicitAny` or `strictNullChecks` on adds a lot of errors and so may require their own work. Additionally they may be easier to add in future, once there is more coverage and definition of types across the tree. The `checkRootOnly` plugin checks only the files that `include` matches and `exclude` doesn't remove. TypeScript still reads the modules those files import, for their types, but doesn't report errors in them. A file that starts with `// @ts-nocheck` stays unchecked even when it is included. ### Include Patterns `include` patterns accept `*`, `?` and `**`, but not braces, so `content/*.js` and `content/*.mjs` are two possible entries. A pattern that matches nothing is fine, as long as the project as a whole matches at least one file. A non-module script, such as one that a page loads with a plain `