问题描述
概述
我正在构建和发布一个在我的项目中使用的自定义 TypeScript 类型声明库。我在将 TypeScript 库导入我的项目时遇到问题。它导入,但我不断收到错误:Module not found
。
我的尝试
src/types/locationTypes.ts
// TypeScript Type: Latitude
export type TLatitude = number;
// TypeScript Type: TLongitude
export type TLongitude = number;
// TypeScript Type: Coordinates
export interface ICoordinates {
latitude: TLatitude;
longitude: TLongitude;
}
src/index.ts
// Imports: TypeScript Types
import * as dateTypes from './types/dateTypes';
import * as locationTypes from './types/locationTypes';
// Exports
export {
dateTypes,locationTypes,};
package.json
{
"name": "@username/custom-types","version": "1.0.0","main": "./dist/index.ts","types": "./dist/index.d.ts","description": "","repository": {
"type": "git","url": "git+https://github.com/username/custom-types.git"
},"publishConfig": {
"registry": "https://npm.pkg.github.com/username"
},"author": "Jeff Lewis","license": "MIT","keywords": [
"typescript","types","component-library",],"scripts": {
"build": "cd src && tsc && cp ../package.json && Echo Build completed!","lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},"devDependencies": {
"eslint": "^7.29.0","typescript": "^4.3.4"
}
}
tsconfig.json
{
"include": ["src/*"],// Specifies an array of filenames or patterns to include in the program
"exclude": [ // Specifies an array of filenames or patterns that should be skipped when resolving include. It is not a mechanism that prevents a file from being included in the codebase - it simply changes what the include setting finds.
"**/__tests__/*","node_modules","babel.config.js","metro.config.js","jest.config.js","compilerOptions": {
"module": "ES6",// Sets the module system for the program. (https://www.typescriptlang.org/docs/handbook/modules.html)
"outDir": "./dist",// If specified,.js (as well as .d.ts,.js.map,etc.) files will be emitted into this directory. The directory structure of the original source files is preserved
"declaration": true,// Generate .d.ts files for every TypeScript or JavaScript file inside your project.
"emitDeclarationOnly": true,// Only emit .d.ts files; Does not emit for .js files. (For TypeScript type deFinition libraries only?)
"typeRoots": ["./node_modules/@types","./dist/index.d.ts"],// If typeRoots is specified,only packages under typeRoots will be included.
"strict": true,// Enable all strict type-checking options.
"strictFunctionTypes": true,// Enable strict checking of function types.
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)