Comments (4)
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.
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.
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.
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)
- When loading the real machine on the mobile terminal in the production environment for the first time, _nuxt/builds/meta/xx.json failed to detch appears. After refreshing the browser, it is normal. Why HOT 4
- definePageMeta doesn't work/ gets ignored HOT 2
- `nuxtRoute` doesn't work at all in Server Components. Hydration error in Universal Components nested in Server Components HOT 1
- Component fails on initial page load, but works after HMR
- V4 - Cannot read properties of undefined (reading 'bind') - @nuxt/kit HOT 2
- Use cookie to custom useFetch composable
- 404 error after running npm run build with app.baseURL set. HOT 5
- useFetch Serialize Type HOT 2
- How to Assign Specific IDs to JavaScript Files Generated by Nuxt.js Build Process HOT 4
- Broken Navigation in Nuxt 3.12.2 - Uncaught (in promise) TypeError: Cannot redefine property: __navigationId at Function.defineProperty (<anonymous>) HOT 1
- HMR routes update
- feat: create new method to utils HOT 3
- navigateTo in $fetch onResponseError is doesn't work HOT 2
- `compatibilityDate` added to the wrong nuxt.config.ts when using layers HOT 2
- Error with webpack builder HOT 3
- Defining `$fetch` within `useFetch()` doesnt pass cookies on SSR HOT 5
- Setting `credentials: 'include'` within `useFetch` cookies are not forwarded on SSR
- Client only component not mounted after nextTick HOT 1
- pnpm pack error after 3.12.3 upgrade HOT 1
- [Server components] Hydration mismatch and failed teleport with nuxt-client and nuxtlink
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nuxt.js.