gtap-dev / javascript

JavaScript Style Guide
MIT License
0 stars 0 forks source link

Type imports #29

Open mjomble opened 1 month ago

mjomble commented 1 month ago

What are your thoughts on type imports?

They don't seem to offer too much in functionality, but might be useful for readability, letting you see right away which imports are types and which ones aren't.

I've sort of started using them because VS Code started adding them to automatic imports by default and I haven't disabled it (yet). But I don't have a clear preference for conventions on when and how to use them.

For example, should we prefer

import { type Type1, type Type2 } from './file'

or

import type { Type1, Type2 } from './file'

The second version seems nice until you need to import both types and non-types from a file. Then you'd have to use two separate imports:

import type { ButtonProps } from './file'
import { Button } from './file'

And the first option starts looking better:

import { Button, type ButtonProps } from './file'

Or should we maybe disallow them entirely?

import { Button, ButtonProps } from './file'
mjomble commented 1 month ago

PS. If we go with separate imports, we'll also need to update the Only import from a path in one place rule.