@lightspeed/config-typescript v2.0.3
@lightspeed/config-typescript
Introduction
TypeScript configuration in a convenient package for services and libraries.
Features
- ✨ Enables TypeScript for typechecking alongside Babel (requires
@lightspeed/babel-preset-webor@lightspeed/babel-preset-nodepackages) in your app or library - 🚀 Emit types for external libraries
- ➡ Absolute path resolving for root
src:
// From anywhere in your app, this will resolve to `<root>/src/components/MyComponent.(js,ts,jsx,tsx)
import { MyComponent } from 'src/components/MyComponent';Installation
First, install required dev dependencies:
yarn add -D typescript @lightspeed/config-typescriptServices
For projects that uses Babel as a transpiler and TypeScript for type-checking.
Install and setup
@lightspeed/babel-preset-web(or@lightspeed/babel-preset-nodeif in a Node.js project)Consume the TypeScript configuration by creating a
tsconfig.jsonat the root of your project, and definebaseUrlincompilerOptionsfor path aliasing to work:
{
"extends": "@lightspeed/config-typescript/tsconfig.service",
"compilerOptions": {
"baseUrl": "."
}
}Note: Extending
tsconfig.jsonfrom a package innode_modulesrequires dependencytypescript@^3.2.2.
- Optionally, extend the configuration as you see fit (but don't forget to keep
baseUrl)
{
"extends": "@lightspeed/config-typescript/tsconfig.service",
"compilerOptions": {
"baseUrl": ".",
"allowJs": true
}
}Nest.js
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.
- Consume the TypeScript configuration by creating a
tsconfig.jsonat the root of your project, and definebaseUrlincompilerOptionsfor path aliasing to work:
{
"extends": "@lightspeed/config-typescript/tsconfig.nest",
"compilerOptions": {
"baseUrl": ".",
"outDir": "./dist"
}
}Libraries
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):
{
"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.