tameemsafi / typewriterjs

A simple yet powerful native javascript plugin for a cool typewriter effect.
https://www.npmjs.com/package/typewriter-effect
MIT License
2.46k stars 220 forks source link

Add types for `state` and other properties #141

Closed jimmycrequer closed 1 year ago

jimmycrequer commented 2 years ago

Thanks for providing this very convenient library !

I found out about this issue mentioning about the state property, holding the eventQueue array.

When I printed out the object to see the available properties, I found out that a lot of them weren't declared in the type :

Screenshot from 2022-03-03 15-15-12

My goal is to simulate a game dialog behavior where clicking on a message being typed out would just show it entirely. For this purpose I am clearing the eventQueue manually to remove all pending events and write out the whole message at once.

https://jsfiddle.net/eszvo40g/1/

However, Typescript complains because state is not defined in the TypewriterClass class. My workaround is currently to extend the type by myself :

type TypewriterClassExtended = TypewriterClass & { state: { eventQueue: [] } };

Would it be possible to add all missing properties in the TypewriterClass class?

tameemsafi commented 1 year ago

The state object is supposed to be private therefore should not be included in the external types. This is because it may change in the future.