Typescript 如何为非类型化的npm模块定制一组d.ts文件?

Typescript 如何为非类型化的npm模块定制一组d.ts文件?,typescript,typescript-typings,Typescript,Typescript Typings,我需要根据需要定制一个现有的@types/three。 我在我的src/typings和npm rm@types/three中克隆了整个@types/threetsconfig.json同时查看node_modules/@types和src/typings 但是,声明模块没有解析为“三” 这是打字/three/index.d.ts: export * from "./three-core"; export * from "./three-canvasrenderer"; export * fr

我需要根据需要定制一个现有的
@types/three
。 我在我的
src/typings
npm rm@types/three
中克隆了整个
@types/three
tsconfig.json
同时查看
node_modules/@types
src/typings

但是,声明模块没有解析为“三”

这是
打字/three/index.d.ts

export * from "./three-core";

export * from "./three-canvasrenderer";
export * from "./three-colladaLoader";
export * from "./three-copyshader";
export * from "./three-css3drenderer";
export * from "./three-ctmloader";
export * from "./three-ddsloader";
export * from "./three-editorcontrols";
export * from "./three-effectcomposer";
export * from "./three-examples";
export * from "./three-fbxloader";
export * from "./three-FirstPersonControls";
export * from "./three-maskpass";
export * from "./three-mtlloader";
export * from "./three-objloader";
export * from "./three-octree";
export * from "./three-orbitcontrols";
export * from "./three-orthographictrackballcontrols";
export * from "./three-outlinepass";
export * from "./three-projector";
export * from "./three-renderpass";
export * from "./three-shaderpass";
export * from "./three-smaapass";
export * from "./three-trackballcontrols";
export * from "./three-transformcontrols";
export * from "./three-vrcontrols";
export * from "./three-vreffect";

// export * from "./three-gltfloader";

export declare module 'three';
// [ts] 'export' modifier cannot be applied to ambient modules and module augmentations since they are always visible.    
// AND
// [ts] Invalid module name in augmentation. Module 'three' resolves to an untyped module at '/Users/abc_user/Desktop/abc_project/node_modules/three/build/three.js', which cannot be augmented.

// export as namespace THREE;
// This has no errors but does not resolve to 'three, meaning when I import * as THREE from 'three', ts says no declaration file exists.

所以问题是:如何为非类型化npm模块定制一组d.ts文件?

您已经了解了其中的大部分内容。您很可能还没有更新您的tsconfig。您需要显式设置typescript编译器可以在何处找到您自己的键入

将此添加到tsconfig.json:

    "paths": {
        "*": [
            "node_modules/*",
            "src/typings/*"
        ]
    },

你已经猜出了大部分。您很可能还没有更新您的tsconfig。您需要显式设置typescript编译器可以在何处找到您自己的键入

将此添加到tsconfig.json:

    "paths": {
        "*": [
            "node_modules/*",
            "src/typings/*"
        ]
    },