mrousavy / nitro

🔥 Insanely fast native C++, Swift or Kotlin modules with a statically compiled binding layer to JSI
https://nitro.margelo.com
MIT License
671 stars 22 forks source link

Nitrogen can't parse types created with `type` instead of `interface` #16

Closed jpudysz closed 3 months ago

jpudysz commented 3 months ago

I'm trying to generate some example bindings, but there's one case where nitrogen didn't detect the correct type or threw an invalid error:

type Dimensions = {
    readonly width: number
    readonly height: number
}

export interface UnistylesRuntime extends HybridObject<{ ios: 'c++', android: 'c++' }> {
    readonly colorScheme: string
    readonly hasAdaptiveThemes: boolean
    readonly screen: Dimensions

    setTheme(themeName: string): void
}

Error:

⚙️   Generating specs for HybridObject "UnistylesRuntime"...
    ❌  Failed to generate spec for UnistylesRuntime! Error: Anonymous objects cannot be represented in C++! Extract "Dimensions" to a separate interface/type declaration.

Changing it to interface works correctly. If you want I can take a look and try to fix that!

mrousavy commented 3 months ago

Hm, interesting. Maybe we can still somehow get a symbol here? I'll play around with this!

https://github.com/mrousavy/react-native-nitro/blob/7a914cf1e7b6daaa87fa91922928c4c6a9deeb3d/packages/nitrogen/src/syntax/createType.ts#L221-L224

mrousavy commented 3 months ago

Closing as I don't see another API in ts-morph for this - I guess it only works on interface right now. I think that's a fair requirement, and not a limitation at all.