Piotr KrzemiĆski
06/02/2021, 11:35 AMjsGenerateExternals from within TypeScript. A minimal example: my d.ts file starts like this
type Nullable<T> = T | null | undefined
export namespace com.example.myproject {
class CoolDto {
constructor(isDog: string);
readonly isDog: string;
// ...
and in TS I import it like this:
import { com } from '../../sharedModel';
const { CoolDto } = com.example.myproject;
type CoolDto = typeof CoolDto;
and then simply use it this way:
coolDtoInstance.isDog
but IntelliJ and TS compiler are complaining:
Property 'isDog' does not exist on type 'typeof CoolDto'. TS2339
73 |
> 74 | const isDog = coolDtoInstance.isDog;
| ^
The funny thing is that IntelliJ hints to add this field to this d.ts file, but after adding it, it still doesn't work đ
Any ideas?Derek Ellis
06/02/2021, 1:18 PMPiotr KrzemiĆski
06/02/2021, 1:22 PMpackage com.example.myproject
import kotlinx.serialization.Serializable
import kotlin.js.ExperimentalJsExport
import kotlin.js.JsExport
@Serializable
@JsExport
@ExperimentalJsExport
data class CoolDto(
val isDog: String
)Derek Ellis
06/02/2021, 1:31 PMisDog with @JsName("isDog")Derek Ellis
06/02/2021, 1:33 PMPiotr KrzemiĆski
06/02/2021, 2:02 PM@JsName(...) doesn't change anything đ the first code snippet is what the Kotlin compiler generates. I realized it's not really a Kotlin problem (đ¶), but consuming some d.ts file from TypeScript. If we get this to work, next we can think if Kotlin correctly generates d.tsDerek Ellis
06/02/2021, 2:19 PMtypeof CoolDto?
You should be able to just use CoolDto as-isPiotr KrzemiĆski
06/02/2021, 2:23 PMTS2749: 'CoolDto' refers to a value, but is being used as a type here. Did you mean 'typeof CoolDto'?
I'm getting it when trying to use CoolDto e.g. in such context:
type SomeCoolReactState = {
coolDtoState: CoolDto | null,
}Piotr KrzemiĆski
06/02/2021, 2:25 PMimport { com } from '../../sharedModel';
const { CoolDto } = com.example.myproject;
And when I try a regular import :
import CoolDto = com.example.myproject.CoolDto;
then the TypeScript compiler complains with such message:
`import =` is not supported by @babel/plugin-transform-typescript
Please consider using `import <moduleName> from '<moduleName>';` alongside Typescript's --allowSyntheticDefaultImports option.
From what I checked, it's not possible to use import when namespaces are used đ€Derek Ellis
06/02/2021, 2:29 PM--allowSyntheticDefaultImports optionDerek Ellis
06/02/2021, 2:29 PM"allowSyntheticDefaultImports":Â true to your tsconfig.json fileDerek Ellis
06/02/2021, 2:29 PMimport CoolDto = com.example.myproject.CoolDto;Piotr KrzemiĆski
06/02/2021, 2:30 PM"allowSyntheticDefaultImports": true, in tsconfig.jsonPiotr KrzemiĆski
06/02/2021, 2:30 PMPiotr KrzemiĆski
06/02/2021, 2:33 PMDerek Ellis
06/02/2021, 2:34 PMDerek Ellis
06/02/2021, 2:34 PMPiotr KrzemiĆski
06/02/2021, 2:36 PMfalse, the code on the main branch doesn't build.
Anyway, thanks a lot for your help so far! will revisit this topic next week.Piotr KrzemiĆski
06/08/2021, 1:36 PMyarn build and you'll see the issue I'm facing. I'd be really grateful if you could take a look @Derek EllisDerek Ellis
06/08/2021, 1:57 PM@babel/plugin-transform-typescript which doesn't like the import = syntax. My project is set up using webpack and we don't use babel which I guess is how I've avoided this issueDerek Ellis
06/08/2021, 2:00 PMDerek Ellis
06/08/2021, 2:00 PMbabel-plugin-replace-ts-export-assignment pluginPiotr KrzemiĆski
06/08/2021, 2:03 PMexport =? the problematic part is import =Piotr KrzemiĆski
06/08/2021, 2:03 PMDerek Ellis
06/08/2021, 2:04 PMDerek Ellis
06/08/2021, 2:13 PMimport { Cat } from "com/github/krzema12/api"Derek Ellis
06/08/2021, 2:14 PMtsc itself instead of babelDerek Ellis
06/08/2021, 2:14 PMPiotr KrzemiĆski
06/08/2021, 2:18 PMDerek Ellis
06/08/2021, 2:25 PMDerek Ellis
06/08/2021, 2:25 PMPiotr KrzemiĆski
06/08/2021, 2:42 PMPiotr KrzemiĆski
06/08/2021, 7:19 PMPiotr KrzemiĆski
06/09/2021, 8:13 AM