halfnelson / nativescript-source-to-jsx-def

Walk nativescript source to generate JSX types for `svelte-type-checker-vscode`
Other
4 stars 1 forks source link

Update typings for NativeScript v8.0.2 #23

Closed shirakaba closed 3 years ago

shirakaba commented 3 years ago

Looks like the Pro UI components didn't really change.

As expected, the Tabs and BottomNavigation components (and subcomponents), are removed.

shirakaba commented 3 years ago

Note: The typings give compiler errors:

// This is the auto-generated type:
type CoreTypes = import("@nativescript/core").CoreTypes;

// ...

// This is the compiler error:
androidContentInset?: string | number | CoreTypes.LengthDipUnit | CoreTypes.LengthPxUnit;
//                                      ^ Cannot find namespace 'CoreTypes'. ts(2503)
// Exported type alias 'ActionBarAttributes' has or is using private name 'CoreTypes'. ts(4081)

This is because @nativescript/core/core-types/index.d.ts uses export namespace, so it's a namespace rather than an interface that's being imported, for once:

https://github.com/NativeScript/NativeScript/blob/272ac578b1e75e7abe61e7294aa250cd08b48110/packages/core/core-types/index.d.ts#L4

We can solve this using:

// Approach 1 – type import:
// I think that the use an import might change the declaration from script context to module context,
// so might be a no-go for Svelte Native; I'm not really sure whether type imports work that way.
import type { CoreTypes } from "@nativescript/core";

// Approach 2 – reconstruct the namespace as a type, property-by-property:
type CoreTypes = {
    LengthDipUnit: import("@nativescript/core").CoreTypes.LengthDipUnit,
};

I'm working around this manually at present.

shirakaba commented 3 years ago

The remaining errors, can be fixed by these manual changes:

- type CSSShadow = import("@nativescript/core").CSSShadow;
+ type CSSShadow = import("@nativescript/core/ui/styling/css-shadow").CSSShadow;

- type NavigationData = import("@nativescript/core").NavigationData;
+ type NavigationData = import("@nativescript/core/ui/frame").NavigationData;

- type SelectedIndexChangedEventData = import("@nativescript/core").SelectedIndexChangedEventData;
+ type SelectedIndexChangedEventData = import("@nativescript/core/ui/segmented-bar").SelectedIndexChangedEventData;

- type TabViewSelectedIndexChangedEventData = import("@nativescript/core").SelectedIndexChangedEventData;
+ type TabViewSelectedIndexChangedEventData = import("@nativescript/core/ui/tab-view").SelectedIndexChangedEventData;
halfnelson commented 3 years ago

Awesome, I had a branch I had not pushed that have some of these changes, but they are still manual fixes. I'll have a crack at detecting and automating the namespace fields