haxiomic / dts2hx

Converts TypeScript definition files (d.ts) to haxe externs (.hx) via the TypeScript compiler API
MIT License
134 stars 9 forks source link

This gets confused by "import type" #107

Open thomasjwebb opened 2 years ago

thomasjwebb commented 2 years ago

I'm trying to use this with antd and get a barrage of errors but it starts with:

Duplicate identifier 'type'. (/Users/pinkboi/src/oea/node_modules/@ant-design/icons/lib/components/AntdIcon.d.ts:2:8)

And if you look where in the typescript that's happening it's where it's using import type:

import * as React from 'react';
import type { IconDefinition } from '@ant-design/icons-svg/lib/types';
import type { IconBaseProps } from './Icon';

This is perfectly valid ts as far as I can tell but I do wonder if dts2hx using an older version of typescript might have to do with it. Do issues happen with newer versions?

thomasjwebb commented 2 years ago

It looks like it was added in 3.8 so maybe just bumping to version 3.8 will fix it. I'll see if I'm able to get building this on my system and if so I'll try that...

thomasjwebb commented 2 years ago

It seems updating the version fixes this. I still have other issues which I don't think are from this tool:

> Error: [TypeScript 4.5] [object Object] (/Users/pinkboi/src/oea/node_modules/@ant-design/icons/lib/components/Icon.d.ts:19:78)
> Error: [TypeScript 4.5] Cannot find namespace 'JSX'. (/Users/pinkboi/src/oea/node_modules/@ant-design/react-slick/types.d.ts:37:41)
> Error: [TypeScript 4.5] Cannot find namespace 'JSX'. (/Users/pinkboi/src/oea/node_modules/@ant-design/react-slick/types.d.ts:47:35)

but at least that issue goes away. Are there any downsides to at least upgrading to the latest typescript 3 version, 3.9.4?

haxiomic commented 2 years ago

Hey thanks for testing updating to 3.8! That’s a super useful datapoint. 3.9.4 may well work too

I’ve been holding back doing this in the main repo because I wanted to go change by change through the compiler API to see if anything critical comes up (since the ts compiler API was a WIP at the time)

however if it works for you maybe we can release it as an alpha version so people can use it in the short term

haxiomic commented 2 years ago

If the dts2hx tests are happy on 3.8 or 3.94 let’s deploy it to release

thomasjwebb commented 2 years ago

Oh yeah I ended up testing with 3.9.4 and that worked for me (aside from other issues I had, which I think are specific to me and not caused by dts2hx).

haxiomic commented 2 years ago

That’s good news :), i’ll try it early Jan and if it passes the tests I’ll push a new release

@PXshadow - looks like 3.9.4 may work out of the box

haxiomic commented 2 years ago

Hey, @PXshadow has let me know about downlevel-dts which can translate TS 4 to TS 3.4 syntax, which could help solve these issues in the short term

PXshadow commented 2 years ago

Thanks for the mention @haxiomic , I'm sure dts2hx could use downlevel-dts as a first compile step assuming it's fast enough and covers the spec better, And in addition as documentation for how to compile new TS 4 syntax.