typewriterjs
typewriterjs copied to clipboard
Cannot find Typewriter when installing through npm
Hello, I have a project that uses Vite with Typescript. When I install TypewriterJs through then I can't import it because Typewriter is no where to be found.
you should import TypewriterComponent
Index.d.ts suggests the TypewriterClass to be a named export, but it isn't and will throw an error when used.
import { TypewriterClass } from "typewriter-effect";
const typewriter = new TypewriterClass(myElement, {
loop: true,
delay: 75,
});
// -> TypeError: TypewriterClass is not a constructor
Im still working on getting it fully working... but @wolkemann this solved my issue:
tsconfig.json
{
"compilerOptions": {
"esModuleInterop": true,
...
and I import and use it like so:
import Typewriter from 'typewriter-effect/dist/core';
...
new Typewriter('#typewriter', {
strings: this.splitNarr(),
autoStart: true,
})
.callFunction(() => {
console.log('String typed out!');
});
I have "esModuleInterop": true
but getting this error in Svelte:
Could not find a declaration file for module 'typewriter-effect/dist/core'. 'path/to/node_modules/typewriter-effect/dist/core.js' implicitly has an 'any' type.
Try `npm i --save-dev @types/typewriter-effect` if it exists or add a new declaration (.d.ts) file containing `declare module 'typewriter-effect/dist/core';`
However, there is no such package @types/typewriter-effect
-- how did you guys solve this TS error?
UPDATE: I solved it by adding this to vite-env.d.ts
:
declare module 'typewriter-effect/dist/core';
In my TS project I've managed to both get rid of import error and to enable typewriter-effect code completion by adding the following to vite-env.d.ts
:
declare module "typewriter-effect/dist/core" {
const Typewriter: typeof import("typewriter-effect").TypewriterClass;
export default Typewriter;
}
In my TS project I've managed to both get rid of import error and to enable typewriter-effect code completion by adding the following to
vite-env.d.ts
:declare module "typewriter-effect/dist/core" { const Typewriter: typeof import("typewriter-effect").TypewriterClass; export default Typewriter; }
I think, adding this to this repo's index.d.ts
should make it work out of the box, shouldn't it?