我目前正在学习TypeScript并尝试定义自己的类型。我目前正在使用.d.ts文件声明我的类型。
我创建了一个文件./src/typings/git-types.d.ts:
declare module "git-types" {
export interface GitRepoListItem {
repoName: string;
repoPath: string;
}
export interface GitReturnObject {
value: any;
errorCode: GitErrorCode;
}
export enum GitErrorCode {
UnknownError = 1,
GitNotFound = 2,
NoValidPathGiven = 3,
LocalChangesPreventCheckout = 4,
LocalChangesPreventPull = 5
}
export interface GitCommit {
hash: string;
author: string;
commitDate: string;
commitTime: string;
commitMessage: string;
}
}
现在,我尝试导入此模块,以便在另一个文件中使用我的类型CommitHistory.ts:
import { GitCommit } from "git-types";
class CommitHistory {
commitList: GitCommit[] = [];
...
}
但是,当我尝试运行代码时,编译器将失败,并出现以下错误: Module not found: Can't resolve 'git-types' in './src/CommitHistory.ts
正如您在我的tsconfig.json-file文件中看到的那样,包括了整个“ src”文件夹:
{
"compilerOptions": {
"target": "es6",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"experimentalDecorators": true
},
"include": ["src"]
}
我必须如何声明模块才能使用我的类型?
相关分类