typewriterjs icon indicating copy to clipboard operation
typewriterjs copied to clipboard

Cannot find Typewriter when installing through npm

Open wolkemann opened this issue 2 years ago • 6 comments

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.

wolkemann avatar May 10 '22 23:05 wolkemann

you should import TypewriterComponent

hamzajamshed152 avatar Aug 17 '22 11:08 hamzajamshed152

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

josias-r avatar Aug 20 '22 09:08 josias-r

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!');
    });    

Shadowstep33 avatar Oct 13 '22 19:10 Shadowstep33

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';

thdoan avatar Oct 23 '23 00:10 thdoan

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;
}

zakutnya avatar Feb 12 '24 18:02 zakutnya

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?

jneuendorf-i4h avatar May 15 '24 10:05 jneuendorf-i4h