Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import type, missing "type" keyword #74

Open
sitnarf opened this issue Feb 26, 2019 · 9 comments
Open

Import type, missing "type" keyword #74

sitnarf opened this issue Feb 26, 2019 · 9 comments

Comments

@sitnarf
Copy link

sitnarf commented Feb 26, 2019

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.

@goodmind
Copy link
Contributor

goodmind commented Mar 9, 2019

@sitnarf .ts file or .d.ts ?

@ahem
Copy link

ahem commented Sep 4, 2019

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;

@goodmind
Copy link
Contributor

goodmind commented Sep 4, 2019

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

@stropho
Copy link

stropho commented Nov 8, 2019

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

@sitnarf sitnarf closed this as completed Nov 8, 2019
@sitnarf
Copy link
Author

sitnarf commented Nov 8, 2019

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

@sitnarf sitnarf reopened this Nov 8, 2019
@chrisdopuch
Copy link

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';

@zxbodya
Copy link
Contributor

zxbodya commented Jul 26, 2020

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 zxbodya@823d624 (based on #115 but should be easy to backport)

@veerabio
Copy link

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",

@zxbodya
Copy link
Contributor

zxbodya commented Dec 10, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants