GithubHelp home page GithubHelp logo

Comments (12)

karlhorky avatar karlhorky commented on June 22, 2024 1

Ok, although I'm not sure if that's the best solution, since highlight-words is broken already now for consumers with TypeScript 4.7+ and this option (TS 5.0 will be coming out soon, so 4.7 is not all that new anymore).

@andrewbranch also mentioned over here that also providing *.d.mts files is the correct solution for library declaration files:

postcss/postcss#1814 (comment)

from highlight-words.

karlhorky avatar karlhorky commented on June 22, 2024 1

I think my suggestion above of duplicating the dist/highlight-words.d.ts file to dist/highlight-words.d.mts is pretty low effort way of getting a working version published, without having to upgrade highlight-words to TS 4.7.

from highlight-words.

karlhorky avatar karlhorky commented on June 22, 2024

Workaround

It seems that duplicating dist/highlight-words.d.ts to dist/highlight-words.d.mts is one resolution for this issue. I used patch-package to apply this temporarily for my project until there is a proper fix.

Alternative solution

Maybe using the "exports" or "types" fields in package.json may offer a simpler way of doing it without as much duplication...

from highlight-words.

tricinel avatar tricinel commented on June 22, 2024

Hi @karlhorky! Thanks for recreating this :)

It seems that node16 for moduleResolution is only available from Typescript 4.7 onwards (https://www.typescriptlang.org/tsconfig#moduleResolution). I've not moved highlight-words to that version yet. When I will, this problem should go away (but I will also make sure your issue actually goes away as well).

I'll keep this issue open until then.

from highlight-words.

tricinel avatar tricinel commented on June 22, 2024

Still related to Typescript 4.7+, what am I missing? I'm just saying I haven't updated to 4.7+ (and 5.0 is in beta, which I won't migrate to any time soon).

from highlight-words.

karlhorky avatar karlhorky commented on June 22, 2024

What I mean here is that other users may be using versions newer than the version of TypeScript that is used internally in a library. And these newer versions should be supported, even if the library itself does not internally use this newer version yet.

from highlight-words.

tricinel avatar tricinel commented on June 22, 2024

Give this a try, if you want: https://www.npmjs.com/package/highlight-words/v/1.2.2-beta.0. The problem is...the tsc error goes away, but you still don't have declarations. It will complain highlightWords is not callable.

So still working on it, but it's not a priority right now.

from highlight-words.

karlhorky avatar karlhorky commented on June 22, 2024

Oh nice, thanks!

Just took a look, did you mean to also publish the dist/highlight-words.d.mts file I mentioned above in this version?

I don't see it in the unpkg file explorer for [email protected]:

Screenshot 2023-02-02 at 15 18 27

from highlight-words.

tricinel avatar tricinel commented on June 22, 2024

Nope, but in package.json, we have the types prop for exports:

"exports": {
    ".": {
      "types": "./dist/highlight-words.d.ts", <-----
      "require": "./dist/highlight-words.js",
      "default": "./dist/highlight-words.mjs"
    }
  }

which should do the same thing, as far as I understood.

from highlight-words.

andrewbranch avatar andrewbranch commented on June 22, 2024

It’s not the same thing—see the explanation under “Types are CJS, but implementation is ESM” at https://github.com/arethetypeswrong/arethetypeswrong.github.io.

from highlight-words.

tricinel avatar tricinel commented on June 22, 2024

Thanks both! I must admit, I am not familiar with all these since I can't dedicate 100% of my time to it - day job and all you know.

Give [email protected] a try though.

from highlight-words.

karlhorky avatar karlhorky commented on June 22, 2024

[email protected] seems to work for my project with "module": "node16", thanks!

I guess we should leave this issue open until there's a non-beta version published?

from highlight-words.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.