Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I import all flow types at once?

Let's suppose I have this:

import type { Collection } from './x.types.js';
import type { Collection } from './y.types.js';

I would like to import both like this:

import type * as XTypes from './x.types.js';
import type * as YTypes from './y.types.js';

because in my code I will have a namespace, I can easily recognise where they are coming from and I will not have any declaration's conflict.

const something = (collection: Xtypes.collection) => {}
const something2 = (collection: Ytypes.collection) => {}
like image 528
Michael Mammoliti Avatar asked Oct 28 '22 12:10

Michael Mammoliti


1 Answers

You can import everything from the module and access the types like you would any exports from the module:

(Try)

import * as React from 'react'
const a: React.Element<'div'> = <div>Test</div>

I don't think an import type * as ReactTypes syntax exists at the moment. If you use the above syntax, I hope you're using tree shaking or you're already using that module somewhere else. It would be a shame to bloat your deployed code just to use this shorthand import.

like image 58
James Kraus Avatar answered Nov 13 '22 00:11

James Kraus