typle v0.2.1
typle
š¦ Scan and install missing Typescript type definitions for dependencies in package.json
.
Table of Contents
Features
- āļø Highly customazible and easy to use.
- āļø Detects whether a library has built-in typings or provided by DefinitelyTyped
- āļø Supports multiple
package.json
files and monorepos. - āļø Matches version of
@types
with its corresponding package. See here for details. - āļø Installs them with automatically detected package manager or just updates
package.json
file.
Install
Install package either locally in your project or globally:
# locally
npm install typle --save-dev
# globally
npm install typle -g
Alternatively, use npx
directly:
npx typle
Quick start
Run typle in the root of your project with package.json
inside it.
This will scan package.json
for missing typescript declarations and install them:
npx typle
Usage
typle [paths/to/package.json] [--options]
Paths can be either file paths or glob patterns, e.g. typle packages/*
when working with a monorepo.
Install command
typle install <package-names> [--options]
Simply install packages with their corresponding type declarations.\ All flags will be passed to a given package manager's options.
Available under alias i
.
CLI Help
$ typle -h
typle
Usage
$ typle [flags...] [patterns...]
Scan and install missing Typescript type definitions for dependencies in 'package.json'.
Commands
install Install packages with their corresponding type declarations. (alias: 'i')
Options
-h, --help Show help.
-v, --version Get version.
--silent Run install silently.
--install Whether to install packages automatically or just update package.json.
--pkg-manager [manager] Which package manager to use.
--ignore-packages [packages...] List of packages to ignore.
--ignore-deps [deps...] List of certain dependency fields to ignore e.g. 'dev'.
--config [path] Path to the config file.
--dry-run It won't cause any changes to package.json.
Examples
$ typle --ignore-packages nodemon eslint
$ typle packages/*
Options
Options that aren't prefixed with double dash (--
) are strictly for CLI.
Option | Description | Default |
---|---|---|
--silent | Run install silently. | true |
--install | Whether to install packages automatically or just update package.json . | true |
--pkg-manager | Which package manager to use. Allowed: npm, yarn, pnpm or bun. | Automatically detected. |
--ignore-packages | List of packages to ignore. | - |
--ignore-deps | List of certain dependency fields to ignore, e.g. to ignore devDependencies use --ignore-deps devDependencies or --ignore-deps dev for shorthand. | - |
--config | Path to the config file. | - |
--dry-run | If specified, it won't make any changes in package.json or install any packages. | false |
patterns | Paths or globs where package.json files will be scanned. | - |
additionalArgs | Additional arguments for package install. | - |
-v, --version | Show version. | - |
-h, --help | Show help. | - |
Config file
Alternatively, you can use a configuration file instead with the same options in: .typlerc.js
file (or any other config file supported) or typleConfig
field in your package.json
. See lilconfig for more details.\
You might also find use of defineConfig
wrapper function that will help you with defining configuration:
// .typlerc.js
import { defineConfig } from 'typle';
export default defineConfig({
silent: false,
patterns: 'packages/*',
ignorePackages: ['nodemon', 'eslint'],
/** etc... */
});
Supported config file paths
package.json
.typlerc.js
.typlerc.cjs
.typlerc.json
typle.config.js
typle.config.cjs
.config/typlerc
.config/typlerc.json
.config/typlerc.js
.config/typlerc.cjs
.typlerc.ts
.typlerc.mts
.typlerc.cts
typle.config.ts
typle.config.mts
typle.config.cts
.config/typlerc.ts
.config/typlerc.mts
.config/typlerc.cts
If you wish to store config in some other file path use --config
option.
Monorepos
You can use typle in a monorepo too!
āāāā typle (root folder)
āāāā packages
ā āāāā typle
ā āāāā typle-core
ā āāāā typle-util
āāāā .typlerc.json
āāāā package.json
In this example monorepo, in order to scan every folder in packages
directory we can use the following config:
// .typlerc.json
{
"patterns": "packages/*"
}
Then run typle
in the root directory.
Why?
Installing typings manually is just annoying and sometimes quite vague.
Acknowledgements
Typle was heavly inspired by typesync, but with many improvements and new features.
License
MIT š