$ npm install @ts-type/package-dts
NPM 配置文件(package.json、.eslintrc.json、tsconfig.json、.travis.yml)的 TypeScript 類型定義
TypeScript type definitions for NPM configuration files (package.json, .eslintrc.json, tsconfig.json, .travis.yml)
npm install @ts-type/package-dts
# or
yarn add @ts-type/package-dts
import IPackageJson from '@ts-type/package-dts/package-json';
import { readPackageJson } from '@ts-type/package-dts';
// 讀取 package.json
const pkg = readPackageJson('./package.json');
// 使用類型
const name: string = pkg.name;
const version: string = pkg.version;
const keywords: string[] = pkg.keywords ?? [];
// 驗證類型
const devDeps = pkg.devDependencies;
if (devDeps) {
Object.keys(devDeps).forEach(dep => {
console.log(`${dep}@${devDeps[dep]}`);
});
}

© 2010 - cnpmjs.org x YWFE | Home | YWFE