question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't import custom type definitions

See original GitHub issue

Type of Issue

[x ] Bug Report
[x ] Feature Request
(not sure if this is a bug, or a missing feature... or if I'm just doing it wrong)

Description

I have been using a JS library (d3-context-menu) successfully with ng-packagr up until now. Since upgrading to Typescript 4.4.2 I can’t use the require syntax anymore for that version, so I’m forced to created a type definition file. However, I cannot get my project to use this type definition at all. It will work with another project that doesn’t use ng-packagr, so there must be something I’m missing to get that type definition to work.

Help? See here for a more detailed description of the problem, with screenshots: https://stackoverflow.com/questions/71178933/how-to-get-ng-packagr-to-recognize-a-typescript-type-definition

Here is the repro app https://github.com/alexanderlevitsky/repro-app

How To Reproduce

Import a JS library such as d3-context-menu and create a type definition for it. Attempt to compile the project.

Expected Behaviour

Type definition should be recognized and allow the library to be used as it could be before, with the require syntax.

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr: 13.2.0
@angular/*: 13
typescript: 4.4.2

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
alan-agius4commented, Mar 2, 2022

Thinking about this a bit more, since this is a library including .d.ts would require consumers to enable skipLibCheck which isn’t great.

Therefore a better way to use custom type definitions in a library is use the Triple-Slash Directives .

Rename decs.d.ts to src/decs.ts and In src/lib/menu.service.ts add /// <reference path="../decs.ts" />.

0reactions
github-actions[bot]commented, Apr 28, 2022

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to correctly import custom types in typescript
You can fix this by changing @types to something like @customTypes or by changing the path for your types folder something like @src/types......
Read more >
TypeScript: Adding Custom Type Definitions for Existing ...
In these circumstances, you have to add your own custom type definitions for the libraries. This article will show you how to that....
Read more >
Cannot Load Custom Definition File in Repository #23185
I am importing a JavaScript library that doesn't have any definition file. I want to create a custom definition file that I place...
Read more >
Adding Custom Type Definitions to a Third-Party Library
1. Edit your tsconfig file to use the typeRoots property. · 2. Add that root folder to the exclude property in the tsconfig...
Read more >
Documentation - Modules .d.ts - TypeScript
The types which are exported can then be re-used by consumers of the modules using either import or import type in TypeScript code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found