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 definition issue

See original GitHub issue

I’m getting a TS error about: Cannot invoke an expression whose type lacks a call signature.

From what I found out, using the following typedef locally works fine:

declare module 'clipboard-copy' {
  function clipboardCopy (text: string): Promise<void>
  export default clipboardCopy
}

I’m on Typescript 3.2.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
LinusUcommented, Jan 18, 2019

@gfx that wouldn’t make a difference since in that case, we would do export = function clipboardCopy (text) { ... } to maintain compatibility with the current ecosystem.

Until ES modules become stable and widely used in Node.js I think that we’ll stick with CommonJS style ☺️

1reaction
LinusUcommented, Dec 11, 2018

The vast majority of the code on Npm uses module.exports = ... and the correct way to import them are import ... = require('...'). Depending on how you have configured TypeScript or your bundler it might work with import ... from '...' also…

When I’m using import copyToClipboard from 'clipboard-copy' I’m getting:

index.ts:1:8 - error TS1192: Module '"/private/tmp/djaskd/node_modules/clipboard-copy/index"' has no default export.

1 import copy from 'clipboard-copy'
         ~~~~


Found 1 error.

If I pass --esModuleInterop to tsc it works. Do you have esModuleInterop in your tsconfig?


You can also see the difference in the output:

import copy from 'clipboard-copy'
copy('test')

becomes:

var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
var clipboard_copy_1 = __importDefault(require("clipboard-copy"));
clipboard_copy_1["default"]('test');

whilst,

import copy = require('clipboard-copy')
copy('test')

becomes

var copy = require("clipboard-copy");
copy('test');

In both cases the typings works correctly for me…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - Type Declarations - TypeScript
TypeScript includes declaration files for all of the standardized built-in APIs available in JavaScript runtimes. This includes things like methods and ...
Read more >
Typescript Definition · Issue #126 · React95/React95 - GitHub
I plan to use this package in an upcoming Reason project, so I'd rather not reimplement the type definitions by writing bindings, if...
Read more >
Issues for TypeScript definitions | Drupal.org
Title Status Priority Category Component Re... Usage example Active Normal Feature request Documentation 3 Definitions for core modules ‑ views_ui Active Normal Feature request Code...
Read more >
Typescript definition issue for npm package for node and ...
The problem is I am running under typescript environment. So in the node client, I can consume the library just fine. This is...
Read more >
TypeScript Programming with Visual Studio Code
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It offers classes, modules, and interfaces to help you build robust...
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