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

Type error in 'svgmoji/emoji.json': Type 'number' is not assignable to type 'Presentation'.ts(2322) #26

Open
mauriciabad opened this issue Nov 27, 2023 · 1 comment

Comments

@mauriciabad
Copy link

mauriciabad commented Nov 27, 2023

Summary

The type definitions of the library are wrong, because the example code gives errors.

Steps to reproduce

import { Notomoji } from '@svgmoji/noto'
import data from 'svgmoji/emoji.json'

const notomoji = new Notomoji({ data, type: 'individual' })

Expected results

No type errors.

Actual results

This error:

Type '({ annotation: string; hexcode: string; emoji: string; text: string; type: number; version: number; shortcodes: string[]; tags?: undefined; order?: undefined; group?: undefined; subgroup?: undefined; emoticon?: undefined; skins?: undefined; tone?: undefined; gender?: undefined; } | ... 8 more ... | { ...; })[]' is not assignable to type 'FlatEmoji[] | MinifiedEmoji[]'.
 Type '({ annotation: string; hexcode: string; emoji: string; text: string; type: number; version: number; shortcodes: string[]; tags?: undefined; order?: undefined; group?: undefined; subgroup?: undefined; emoticon?: undefined; skins?: undefined; tone?: undefined; gender?: undefined; } | ... 8 more ... | { ...; })[]' is not assignable to type 'FlatEmoji[]'.
   Type '{ annotation: string; hexcode: string; emoji: string; text: string; type: number; version: number; shortcodes: string[]; tags?: undefined; order?: undefined; group?: undefined; subgroup?: undefined; emoticon?: undefined; skins?: undefined; tone?: undefined; gender?: undefined; } | ... 8 more ... | { ...; }' is not assignable to type 'FlatEmoji'.
     Type '{ annotation: string; hexcode: string; emoji: string; text: string; type: number; version: number; shortcodes: string[]; tags?: undefined; order?: undefined; group?: undefined; subgroup?: undefined; emoticon?: undefined; skins?: undefined; tone?: undefined; gender?: undefined; }' is not assignable to type 'FlatEmoji'.
       Types of property 'type' are incompatible.
         Type 'number' is not assignable to type 'Presentation'.ts(2322)
base-moji.d.ts(7, 5): The expected type comes from property 'data' which is declared here on type 'MojiProps'

Possible Solution

Fix the types.

Either change the union type of Presentation from 1 | 2 to number, or update the type of svgmoji/emoji.json to make sure that type is of type 1 | 2. I think that the second option is the best one, maybe you can import the json file in a ts file, then perform some checks to narrow the types or just use a type cast, and then export the data variable.

@mauriciabad
Copy link
Author

The current workaround is to use as any:

import { Notomoji } from '@svgmoji/noto'
import data from 'svgmoji/emoji.json'

const notomoji = new Notomoji({ data: data as any, type: 'individual' })

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