Comments (11)
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.
@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.
Yes, I can't use this with imports
from debounce.
Import works for me with typescript/webpack.
from debounce.
@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.
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.
@bsg62 doing what you've suggested also gives me the same error. Only
const debounce = require('debounce');
works correctly
from debounce.
@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.
Still the same error :(
from debounce.
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.
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)
- Add raf support HOT 1
- npm version out of date HOT 6
- Allow injecting a custom setTimeout? HOT 2
- can not call my func right now? HOT 2
- arguments get reset if you call debounced function within itself HOT 1
- Debounced function executing early? HOT 2
- snowpack failed to compile. 'debounce' is not exported by node_modules/debounce/index.js, HOT 6
- debounce and throttle seems to decrease performance for window.onscroll HOT 1
- Run debounce() callback if browser tab is closed HOT 1
- Proper testing HOT 2
- Usage of 'date-now' actually makes this harder to test with Jasmine HOT 4
- Add support for promises HOT 8
- Protect against improper use HOT 1
- Provide a way to cancel scheduled debounces HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from debounce.