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.

Typescript implementation doesn't work with individual modules

See original GitHub issue

Expected behavior

You should be able to import the parts of the library individually and types should work. Unfortunately due to the way the types packages are defined this doesn’t currently function. I believe also the current module structure expects a certain layout in the node_modules folders which means this project doesn’t work with alternative node_module package managers like pnpm or yarn workspaces.

https://stackblitz.com/edit/typescript-ff3ss5?file=index.ts

Importing using this form:

import '@interactjs/actions/drag';
import interact from '@interactjs/interact';

Actual behavior

Assuming you’re using npm, then the above will result in a typescript error: Could not find a declaration file for module '@interactjs/interact'

This is because the @interactjs/interact package does not actually define a types field and the index.js has no adjacent index.d.ts in the shipped package.

If you’re using pnpm or other package managers that don’t necessarily put all the scoped packages adjacent to each other, then the form of import used in the @interactjs/interact/index.js will cause issues:

import { Scope } from "../core/scope.js";

This makes the assumption that the @interactjs/interact module is adjacent and findable through the relative module resolution here. Which is not guaranteed to be the case, the correct import would be import { Scope } from '@interactjs/core'.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
Pokerkoffercommented, Apr 27, 2022

not stale

3reactions
tayecommented, Jun 10, 2022

The situation is improved with the latest version. You shouldn’t need to install or import @interactjs/types.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Common TypeScript module problems and how to solve them
A firm understanding of TypeScript modules system. Problem 1: Irregular location of dependencies. On a normal occasion, the node-modules ...
Read more >
Documentation - Modules - TypeScript
Modules are executed within their own scope, not in the global scope; this means that variables, functions, classes, etc. declared in a module...
Read more >
Why can't TypeScript modules implement or adhere to an ...
The reason is that a module is more like an instance instead of being something that can be instantiated (e.g. a class). In...
Read more >
Allow a module to implement an interface · Issue #420 - GitHub
It would be useful when a module can implement an interface using the implements keyword. Syntax: module MyModule implements MyInterface { .
Read more >
TypeScript - Modules - TutorialsTeacher
ts is accessible in file2.ts as well. Not only it is accessible but also it is open to modifications. Anybody can easily override...
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