Common TypeScript configuration for Lightspeed webapps
npm install @lightspeed/config-typescript@lightspeed/config-typescript
TypeScript configuration in a convenient package for services and libraries.
- ✨ Enables TypeScript for typechecking alongside Babel (requires @lightspeed/babel-preset-web or @lightspeed/babel-preset-node packages) in your app or library
- 🚀 Emit types for external libraries
- ➡ Absolute path resolving for root src:
``js
// From anywhere in your app, this will resolve to
import { MyComponent } from 'src/components/MyComponent';
``
First, install required dev dependencies:
`sh`
yarn add -D typescript @lightspeed/config-typescript
For projects that uses Babel as a transpiler and TypeScript for type-checking.
1. Install and setup @lightspeed/babel-preset-web (or @lightspeed/babel-preset-node if in a Node.js project)
2. Consume the TypeScript configuration by creating a tsconfig.json at the root of your project, and define baseUrl in compilerOptions for path aliasing to work:
`json`
{
"extends": "@lightspeed/config-typescript/tsconfig.service",
"compilerOptions": {
"baseUrl": "."
}
}
> Note: Extending tsconfig.json from a package in node_modules requires dependency typescript@^3.2.2.
3. Optionally, extend the configuration as you see fit (but don't forget to keep baseUrl)
`json`
{
"extends": "@lightspeed/config-typescript/tsconfig.service",
"compilerOptions": {
"baseUrl": ".",
"allowJs": true
}
}
For Nest.js backend applications that use TypeScript for transpiling and type-checking. The configuration is stricter than the default generated tsconfig.json from Nest.js boilerplate applications, in particular, enabling the strict option.
1. Consume the TypeScript configuration by creating a tsconfig.json at the root of your project, and define baseUrl in compilerOptions for path aliasing to work:
`json`
{
"extends": "@lightspeed/config-typescript/tsconfig.nest",
"compilerOptions": {
"baseUrl": ".",
"outDir": "./dist"
}
}
For libraries where you want to output types for external consumers, use the following configuration instead (paths may vary depending on your project structure, but those are typical ones):
`json``
{
"extends": "@lightspeed/config-typescript/tsconfig.library",
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist"
},
"include": ["./src//.ts", "./src//.tsx"],
"exclude": ["/.test.ts", "/.test.tsx"]
}
You can still extend as mentioned in the services section.