Giter Site home page Giter Site logo

Types auto-import about nuxt.js HOT 4 OPEN

Ragura avatar Ragura commented on August 21, 2024
Types auto-import

from nuxt.js.

Comments (4)

Ragura avatar Ragura commented on August 21, 2024 2

Oh yeah, absolutely should only look at types inside the types folder (with additional config possible to add folders). But in my project for example, I have differently named files in that folder that still have similarly named types. They would cause collision problems if they were all auto-imported. You're right that full auto-import could come with restraints put on developers to make sure they have unique names, though I'm not sure how practical that would be for existing codebases as well as being difficult to report to the developer when they're creating new types. And there's always the risk that extended layers could use those names inside their types too.

from nuxt.js.

maxdzin avatar maxdzin commented on August 21, 2024

Maybe it would be good to just auto import all the types, rather than selectively (not sure if there are could be some cases when it would be really handful). But optionally.

Having all the TS things to be imported on demand is actually a good practice (maybe to prevent some collisions). But, yes, it is also interesting how it will look like with auto-imports.

When I think about this feature, it reminds me of the previous versions of Nuxt 3 where composables, utils, etc. weren't automatically imported, but now they are, and so it made using Nuxt much easier.

Maybe we will have the same effect with the types to be auto imported? I assume that it wasn't done yet because of some pitfalls or something, probably. @danielroe can you share your thoughts about it?

from nuxt.js.

Ragura avatar Ragura commented on August 21, 2024

I think it hasn't been done because there is no existing unplugin package that does this, unlike for auto-imports of composables and components?

I agree you could make an argument for having to explicitly import types as a best practice, but that argument would then be the same for any imports.

The reason I suggested not importing all types is that there will be many more types than there are functions/components in a project. Imagine the IDE experience with 3000 types being loaded for autocomplete...
But the biggest issue with importing all types indiscriminately is naming collisions. Let's say you have an exported interface FormBody in every form component/composable/api route. How would the auto-import even know which one you're referring to?

I think the greatest strength of this feature would be to take away the workload of importing regularly used common types and improve readability of the top of a file as a result (not having your first actual line of code further down the file).

from nuxt.js.

maxdzin avatar maxdzin commented on August 21, 2024

I think it hasn't been done because there is no existing unplugin package that does this

Ah, indeed

But the biggest issue with importing all types indiscriminately is naming collisions. Let's say you have an exported interface FormBody in every form component/composable/api route. How would the auto-import even know which one you're referring to?

In that case, it will surely require maintaining naming conventions effectively, like ensuring you have unique names, etc.

It seems I need to express more about what I imagined about auto-importing: it is to import everything automatically from the types directory and its subdirectories only.
As for the other types exports, like from components or other places, those things will require to be imported manually.
But I just thinking about how it could be.

from nuxt.js.

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.