Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I make a custom set of d.ts files for my project for an untyped npm module? #20421

Closed
ghost opened this issue Dec 3, 2017 · 2 comments
Closed

Comments

@ghost
Copy link

@ghost ghost commented Dec 3, 2017

I need to customize an existing @types/three as per my needs. I cloned the entire @types/three in my src/typings and npm rm @types/three. tsconfig.json looks at both node_modules/@types and src/typings.

However, the declaration module does not resolve to 'three'.

Here is the 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.

So the question is: How can I make a custom set of d.ts files for an untyped npm module?

@j-oliveras
Copy link
Contributor

@j-oliveras j-oliveras commented Dec 3, 2017

You can use path mapping. In your case, something like:

{
  "compilerOptions": {
    "baseUrl": ".", // This must be specified if "paths" is.
    "paths": {
      "three": ["src/typings/three"] // This mapping is relative to "baseUrl"
    }
  }
}

@ghost
Copy link
Author

@ghost ghost commented Dec 3, 2017

Thanks a lot.
Something similar to this solves the problem.

Adding the paths options solved it.

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

@ghost ghost closed this Dec 3, 2017
jklmli added a commit to jklmli/genesis that referenced this issue Mar 28, 2018
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant