Giter VIP home page Giter VIP logo

Comments (11)

JoshuaKGoldberg avatar JoshuaKGoldberg commented on July 20, 2024 2

create a definition, as suggested here.

Alas, that isn't a workable or future-proof solution. ☹

There's a good reason why TypeScript refuses to acknowledge the type declaration for debounce: what it's doing isn't compatible with ES modules, only CommonJS. ES modules don't allow the exported object to be callable (a function). It can contain members that are functions, but it itself must be an object.

This will not work in systems that properly implement the new spec:

import * as debounce from "debounce";

// This should give an error about not being callable
debounce(...);

...while this is allowed and encouraged:

import { debounce } from "debounce";

debounce(...);

Links in the OP for why this is the case.

from debounce.

JoshuaKGoldberg avatar JoshuaKGoldberg commented on July 20, 2024 1

@ChuckJonas yup, the problem there is that the debounce package was updated but your TypeScript typings in the @types/debounce package were not.

DefinitelyTyped/DefinitelyTyped#29768

Once that PR is merged, as soon as a new version of @types/debounce is published (normally within a few hours) it'll have the right change.

from debounce.

dortamiguel avatar dortamiguel commented on July 20, 2024

Yes, I can't use this with imports

from debounce.

senyaak avatar senyaak commented on July 20, 2024

Import works for me with typescript/webpack.

from debounce.

Szmiglo avatar Szmiglo commented on July 20, 2024

@senyaak How did you managed it to work? I'm also working with TS + webpack and using
import { debounce } from 'debounce';
gives me error

Could not find a declaration file for module 'debounce'. '...\node_modules\debounce\index.js' implicitly has an 'any' type.

from debounce.

bsg62 avatar bsg62 commented on July 20, 2024

Just remove the curly brackets: import debounce from 'debounce'

Debounce has only a default export with module.exports, so you can't use the curly brackets to import certain functions or variables. Take a look at MDN.

from debounce.

Szmiglo avatar Szmiglo commented on July 20, 2024

@bsg62 doing what you've suggested also gives me the same error. Only
const debounce = require('debounce');
works correctly

from debounce.

bsg62 avatar bsg62 commented on July 20, 2024

@Szmiglo Okay, I think I have a solution. I was under the impression, that TypeScript imports work the same as ES6 imports, but that's not the case. My example from above works fine with ES6 and Webpack, but not with TS.

This should work: import * as debounce from 'debounce'

from debounce.

Szmiglo avatar Szmiglo commented on July 20, 2024

Still the same error :(

from debounce.

bsg62 avatar bsg62 commented on July 20, 2024

Well, okay, I'm blind. :D

The import works fine, but TypeScript can't find a type declaration for debounce.

You can either disable noImplicitAny in your TS config or create a definition, as suggested here.

from debounce.

ChuckJonas avatar ChuckJonas commented on July 20, 2024

In ts 3.0.3, when I try import { debounce } from "debounce"; I still get an error [ts] Module '"/Users/jonas/Documents/code/apex-pmd/node_modules/@types/debounce/index"' has no exported member 'debounce'..

If I update the types.d.ts file to look like this it works:

export declare function debounce<A extends Function>(f: A, interval?: number, immediate?: boolean): A & { clear(): void; };

from debounce.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.