kristiandupont / kanel

Generate Typescript types from Postgres
https://kristiandupont.github.io/kanel/
MIT License
867 stars 60 forks source link

IDE error on import {type default as ....}? #542

Closed dangnhdev closed 1 week ago

dangnhdev commented 7 months ago

I tried to research this, but I couldn't find anything about this syntax. Both VSCode and WebStorm show a file error for this. However, tsc compiles it normally. image

How should I address this issue?

Here is my tsconfig.json and .kanelrc.cjs file: https://gist.github.com/dangnhdev/e1946fcad3e02d55cd0a43cdce9157a6

kristiandupont commented 7 months ago

Could it be that you are running an older version of TSC in your IDE than what you have in your package.json? Take a look at this StackOverflow answer.

kennethnym commented 6 months ago

I am using the latest TypeScript (5.4.2) and can confirm this is an issue. WebStorm is picking up the correct version, so it is not an IDE issue. Is there a reason why the generated code prefixes each imported member with type, rather than making the entire import statement type only, since afaik the code will never import non-type members?

instead of:

import { type default as Table } from "..."

generate

import type { default as Table } from "..."
kristiandupont commented 6 months ago

So running tsc fails as well?

Kanel can generate enums which generate "code" as well as types, so those require regular importing. At least, I believe so -- I don't think I've ever actually verified this...

thesmart commented 4 months ago

I'm having the same issue, and also using Webstorm. I upgraded to the latest version which invalidated symbol caches to rerun the code indexer. This seems to have fixed the import { type default issue for me.

I will also note that import { type syntax may result in side-effects:

import { type A, type B } from 'mod';

// is transpiled to

import {} from 'mod';
// which is the same as
import 'mod';

Probably not an issue for kanel because it is default, but import type { would be completely removed in output JS.

kristiandupont commented 4 months ago

This was recently brought to my attention and is a good reason to change the syntax, thank you! However, as I stated earlier, Kanel can in fact generate a bit of code if you use enum, so it would have to check for those. I am considering getting rid of enums altogether as I personally prefer union types but that might upset some people.

kristiandupont commented 3 months ago

I have just published a version that I think should fix this issue. Let me know if it works!