flowgen icon indicating copy to clipboard operation
flowgen copied to clipboard

Import type, missing "type" keyword

Open sitnarf opened this issue 5 years ago • 9 comments

Hi, I have type import in my ts file: import { HttpRequest } from "./httpRequests"

but the generated flow declaration states: import { HttpRequest } from './httpRequests'; instead of import type { HttpRequest } from './httpRequests';

Shouldn't be this automatically transpiled? Tried last flowgen from repo. Thanks.

sitnarf avatar Feb 26 '19 15:02 sitnarf

@sitnarf .ts file or .d.ts ?

goodmind avatar Mar 09 '19 14:03 goodmind

I am experiencing this also (using version 1.10.0). Here is a minimal reproducible example:

a.d.ts

export declare type A = {
    a: string;
};

b.d.ts

import { A } from './a';
export declare const o: A;

Run:

$ npx flowgen ./b.d.ts

Actual Result:

import { A } from "./a";
declare export var o: A;

Expected result:

import type { A } from "./a";
declare export var o: A;

ahem avatar Sep 04 '19 13:09 ahem

I don't think it's possible to know what is imported

goodmind avatar Sep 04 '19 15:09 goodmind

I have a similar problem - but with exports ... meaning all the types are in 1 file

// .d.ts
type ToString = {toString: () => string}
export {ToString}

actual result

// .js.flow
declare type ToString = {
  toString: () => string,
  ...
};
declare export {ToString}

expected result

// .js.flow
declare type ToString = {
  toString: () => string,
  ...
};
declare export type {ToString} // or something that indicates that a type is exported, otherwise flow complains

Is this solvable? Or is there some kind of workaround at least? I see a problem when a file exports both types and declared functions, but it would cool to have such functionality

stropho avatar Nov 08 '19 10:11 stropho

Sorry, I didn't get the notification earlier. I believe, we used .ts files for generating .js.flow.

sitnarf avatar Nov 08 '19 12:11 sitnarf

I am also having the same issue. When I import { MyType } from 'module'; in the d.ts file, it doesn't get transpiled as import type { MyType } from 'module';

chrisdopuch avatar Dec 03 '19 23:12 chrisdopuch

related to this, when having code like: import type { MyType } from 'module';

it is also converted to: import { MyType } from 'module';

tried to make a fix for it here https://github.com/zxbodya/flowgen/commit/823d624aa294cfcd4ef3214b8ec91f42c9460c9f (based on #115 but should be easy to backport)

zxbodya avatar Jul 26 '20 00:07 zxbodya

I see the PR has been merged but I am still having this issue. Which version is this available in? I am using "flowgen": "^1.12.1",

veerabio avatar Dec 10 '20 00:12 veerabio

I see the PR has been merged but I am still having this issue. Which version is this available in? I am using "flowgen": "^1.12.1",

merged PR fixes only particular case of the issue - when there was import type usage in typescript code

zxbodya avatar Dec 10 '20 01:12 zxbodya