Skip to content
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

TypeScript: Type Error when injecting graphemeSplitter on stringSplitter option as per the documented demo #211

Open
kenshanta opened this issue Jan 3, 2024 · 0 comments

Comments

@kenshanta
Copy link

When using an emojis (mac) inside the .typeString() method in a NextJs project, it renders as "?" at first across all browsers (chrome, safari, firefox)

My initial approach to fix this issue - as i discovered emojis are an array of characters and the last character only has the emoji value - was to slice the character to its last index and render that. the issue persisted

My second approach was to use the element and provide the key of the emoji or even the emoji itself inside the element's child. the results i got was [object, Object]

Finally after checking and following up with the documentation and how emojis are implemented, i saw the use of the graphemeSplitter package to create a stringSplitter as such:

const stringSplitter = (string: string) => { const splitter = new GraphemeSplitter() return splitter.splitGraphemes(string) }
using this declared method on the typewritter-effect's stringSplitter option inside a TS file returns an error
Type '(string: string) => string' is not assignable to type '(text: string) => string[]'
And obviously no issues on JS files.

I tried a workaround to introduce an array inside typeString method but that returns another TS error declaring the value MUST be of type string.
I had to alter the node_modules typewriter-effect stringSplitter method to return an expected type string instead of string[]

This issue is mainly focused on the demo provided in the typewriter-effect npm readme emoji splitter demo

Let me know if any additional info is needed to resolve this issue, or if im missing anything

Thanks in advance 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant