最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

我的打字稿类型声明文件不工作

网站源码admin39浏览0评论

我的打字稿类型声明文件不工作

我的打字稿类型声明文件不工作

我尝试学习如何发布打字稿 NPM 包。这是我第一次学习教程,但是,我注意到当我在 typescript node.js 项目中使用该包时,它看不到该包的类型文件。我使用的所有其他 NPM 包都有一个工作类型系统,除了我的。 就像类型安全不起作用一样。这是项目结构:

我有一个名为

easyerrormodule.ts
的文件。这是我定义类型的地方,例如:

export interface comonErrorAttributes{
string?: string[]
number?: number[]
}

export interface commonGeneralErrorRoleAttributes{
role?: string
setRole?: string
}

export interface  stringLengthErrorValueAttributes{
string?: string[]
}

export interface stringLengthErrorShortLengthAttributes{
shortMinLength?: number
shortMaxLength?: number
}

我也有这个文件,我的逻辑叫做

globaltype.ts
;

import { comonErrorAttributes, commonGeneralErrorRoleAttributes, stringLengthErrorValueAttributes, stringLengthErrorShortLengthAttributes, 
stringLengthErrorLongStringLengthAttributes, stringLengthErrorLongStringAttributes} from "./easyerrormodule"

class GlobalErrorClass {
   logics run here
 }

export const errorInstance = new GlobalErrorClass()

我的打字稿配置文件:

 {
 "compilerOptions": {

/* Language and Environment */
"target": "es2015",                                  

/* Modules */
"module": "ES2015",                                
   

/* Emit */
 "declaration": true,                              

// "outFile": "./",                                
 "outDir": "./build/esm",                                

// "allowSyntheticDefaultImports": true,             
"esModuleInterop": true,                             
// "preserveSymlinks": true,                         
"forceConsistentCasingInFileNames": true,            

/* Type Checking */
"strict": true,                                     

/* Completeness */
// "skipDefaultLibCheck": true,                      
"skipLibCheck": true,                                
"typeRoots": ["./node_modules/@types/globaltype.d.ts"]
 },
 }

我的 package.json 文件:

{
 "name": "errorcatchernode",
 "version": "1.0.4",
 "description": "basic error handling module for node basic projects",
  "main": "build/globaltype.js",
  "types": "build/easyerrormodule.d.ts",
  "scripts": {
   "build": "tsc"
   },
  "license": "ISC",
  "devDependencies": {
   "typescript": "^5.0.4"
   }
   }

我错过了什么?

回答如下:
发布评论

评论列表(0)

  1. 暂无评论