New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot Import in TypeScript #335
Comments
If it doesn't work, you can try to import directly from The next version will most likely be rewritten in TypeScript - see typescript branch. I "just" need to find some free time to clean it up and figure out rollup config for all versions (umd es5, es6, non-minified, minified etc.) and how to generate TS declaration files. |
@szimek Can con firm that this still does not work inside a .tsx file.
|
What exactly is in |
@szimek TS handles default exports just fine, the problem is in the @types/signature_pad index.d.ts definitions. |
But this library does not provide TypeScript declaration files. |
@szimek it doesn't? Then what is installed when you do |
I don't know ;) You can see all files being published e.g. here: https://www.jsdelivr.com/package/npm/signature_pad. |
@szimek I just noticed my comment before didn't show the whole install line, because of the |
Looks like you're using a definition file from DefinitelyTyped . If I read the declaration correctly this might work (sorry didn't try it out, I just stumbled upon this issue): |
@strongui I got the same mistake as you. I tried everything in the comments, |
I've just tried it out using TypeScript 2.7.2 and it works fine.
import SignaturePad from 'signature_pad';
new SignaturePad(document.querySelector('canvas'));
<html>
<body>
<canvas style="border: 2px solid #000"></canvas>
<script src="bundle.js"></script>
</body>
</html>
{
"compilerOptions": {
"outDir": ".",
"noImplicitAny": true,
"module": "es6",
"target": "es3"
}
}
module.exports = {
entry: './index.js',
output: { filename: 'bundle.js' },
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: [ '.ts', '.js' ]
}
}; Run |
@szimek thanks it works for me |
Works for me using TypeScript 2.4.2 and importing it like @szimek in the comment above.
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
} |
For those are getting SignaturePad is not a constructor error under the hood of requirejs and webpack (or laravel mix) just use with default, as: |
I just released a beta version that is rewritten in TypeScript. Declaration files are now provided by the library. You can install it using It still uses the default export, but I tested it with Webpack 4 and TypeScript 2.7.2 and it works if I import it using It would be awesome to get some feedback, if it works, if there are any issues etc. |
We're using the beta version in a TypeScript 2.8 app and it works fine. Just minor issues:
|
@StevenBarnettST Fixed! Thanks for reporting these issues. Tomorrow I'll release a new beta version. |
What is the correct way to bind the TYPE/interface of signaturepad to a variable, for autocomplete and ts checking? |
This works for me. Thanks a lot! (Symfony Webpack Encore) |
I did a workaround to get it to work: |
For example, this is how I have to import it: |
This is how I fixed it (in Webpack/Mix)
|
Found a way to make it work but It's not for everyone. I managed it to work using the most basic JS and HTML
It will work, But it's not for everyone. |
For posterity. |
With importmaps setup e.g. I'm just doing |
According to the description, I should be able to import this module into TypeScript as follows:
import * as SignaturePad from 'signature_pad';
TypeScript refuses to recognize this as valid because there isn't an exported module. Please export a module for TypeScript compatibility.
Here is a stack overflow topic regarding this.
The text was updated successfully, but these errors were encountered: