@lightspeed/config-typescript
v2.0.3
Published
Common TypeScript configuration for Lightspeed webapps
Downloads
5,395
Keywords
Readme
@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-web
or@lightspeed/babel-preset-node
packages) 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-typescript
Services
For projects that uses Babel as a transpiler and TypeScript for type-checking.
Install and setup
@lightspeed/babel-preset-web
(or@lightspeed/babel-preset-node
if in a Node.js project)Consume the TypeScript configuration by creating a
tsconfig.json
at the root of your project, and definebaseUrl
incompilerOptions
for path aliasing to work:
{
"extends": "@lightspeed/config-typescript/tsconfig.service",
"compilerOptions": {
"baseUrl": "."
}
}
Note: Extending
tsconfig.json
from a package innode_modules
requires 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.json
at the root of your project, and definebaseUrl
incompilerOptions
for 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.