GithubHelp home page GithubHelp logo

Comments (9)

fatcerberus avatar fatcerberus commented on April 28, 2024 1

For the record:
https://arethetypeswrong.github.io/?p=next%4014.1.3

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 28, 2024 1

What you're describing - that package authors tell TS how their package works - is what's happening, it just happens that next is telling TS the wrong thing.

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 28, 2024

next is inferred to be a CommonJS module because it doesn't have type: "module" in its package.json and doesn't have any other indication that it can be loaded as an ESM module.

See #50058 (comment)

from typescript.

mohd-akram avatar mohd-akram commented on April 28, 2024

I don't fully understand that comment. Next does a default export and I do a default import. It seems simple enough that this should work? Why is the type of next considered when that information is already specified in declaration files via either export = or export default?

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 28, 2024

The comment explains all of this

from typescript.

mohd-akram avatar mohd-akram commented on April 28, 2024

It doesn't address why TypeScript considers type of an imported module rather than simply accepting what module authors specify in their type files. For distinguishing between the export default example and the MyFunction one in your comment, the library author can use export default and export = respectively. This is how it already works in non-Node16 modes.

from typescript.

RyanCavanaugh avatar RyanCavanaugh commented on April 28, 2024

If you write your exports in ESM syntax, but the package itself is CJS (which it is), then Node16 module mode says to respect what the package says, because that's what Node does.

from typescript.

mohd-akram avatar mohd-akram commented on April 28, 2024

@RyanCavanaugh I think that's a mistake. The exports are eventually transformed into ESM imports according to Node.js. Per Node.js, that transformation uses static analysis and its outcome is unknown beforehand. Accepting what the types say lets those who do know - the library authors - inform TypeScript of the final shape of the library.

from typescript.

typescript-bot avatar typescript-bot commented on April 28, 2024

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

from typescript.

Related Issues (20)

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.