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 v14.0 #532

Closed
Saul-Mirone opened this issue Mar 13, 2022 · 5 comments
Closed

Type error in v14.0 #532

Saul-Mirone opened this issue Mar 13, 2022 · 5 comments

Comments

@Saul-Mirone
Copy link
Contributor

Describe the bug

../../node_modules/.pnpm/twemoji@14.0.0/node_modules/twemoji/index.d.ts:32:1 - error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.

32 const twemoji: {

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://github.com/Saul-Mirone/milkdown
  2. git checkout renovate/all
  3. pnpm install && pnpm build --filter=@milkdown/plugin-emoji
  4. See error

Expected behavior
Typescript compile can pass with no error.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Environment
For web, specify your OS and browser version. For mobile, specify device, OS
and version. For libraries, what version of build tools are you using?

Additional context
Add any other context about the problem here.

@BenjaminNolan
Copy link

BenjaminNolan commented Mar 14, 2022

In addition to the above, we're getting a TypeScript error when calling Twemoji.parse() as it is incorrectly typed as returning void here, when it actually returns a string. See scripts/build.js examples, which all return strings. The fix for this bit, at least, is to just change the : void; on 37 to : string;.

@hthetiot
Copy link
Contributor

hthetiot commented Mar 14, 2022

I made PR #533 to address this issue feedbacks.
If you need quick fix you can update tsconfig.json with "twemoji": ["src/twemoji.d.ts"] in "ts-node".moduleTypes section and use the following content for src/twemoji.d.ts.

src/twemoji.d.ts

declare interface TwemojiOptions {
  /**
   * Default: MaxCDN
   */
  base?: string;
  /**
   * Default: .png
   */
  ext?: string;
  /**
   * Default: emoji
   */
  className?: string;
  /**
   * Default: 72x72
   */
  size?: string | number;
  /**
   * To render with SVG use `folder: svg, ext: .svg`
   */
  folder?: string;
  /**
   * The function to invoke in order to generate image src(s).
   */
  callback?(icon: string, options: TwemojiOptions): void;
  /**
   * Default () => ({})
   */
  attributes?(): void;
}

declare type Twemoji = {
  convert: {
    fromCodePoint(hexCodePoint: string): string;
    toCodePoint(utf16surrogatePairs: string): string;
  };
  parse(node: HTMLElement | string, options?: TwemojiOptions): void;
};

declare module 'twemoji' {
  const twemoji: Twemoji;
  export default twemoji;
}

tsconfig.json:

{
    "ts-node": {
        "moduleTypes": {
            "twemoji": ["src/twemoji.d.ts"]
        },
    },
   // ...
}

@hthetiot
Copy link
Contributor

hthetiot commented Mar 14, 2022

I had some weird issue with that tsconfig.json workaround above to override the index.d.ts while fix is not merged, where module types was ignored on Linux (GitHub CI) but not on macOS, in the end I just added skipLibCheck as a temporary workaround for the workaround.

@jdecked
Copy link
Contributor

jdecked commented Mar 14, 2022

Fix is merged now; FWIW I'm happy to merge whatever typescript fixes there are relatively quickly in the future – we don't use TS at Twitter, so there's always a chance that whatever exists for TS types in master is somehow broken or incorrect. Thanks for catching it.

@hthetiot
Copy link
Contributor

hthetiot commented Mar 15, 2022

Thank you @jdecked for quick merge, i have tested twemoji@14.0.1 with typescript@4.5.5 and angular@13.2.6 following syntax works as expected now.

const twemoji = await import('twemoji').then((m) => m.default);

OR

import twemoji from "twemoji";

@Saul-Mirone and @BenjaminNolan all good on your side now using 14.0.1 ?

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

4 participants