Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writing MetadataOptions.properties.type function and object as ts types #406

Open
Revest117 opened this issue Jul 18, 2023 · 0 comments
Open

Comments

@Revest117
Copy link

Currently, when defining properties of type function or object, only these type unsafe definitions are accepted.
The ability to define more specific types would greatly improve the quality and readability of the code.

I have 2 ideas in my mind how this could be achieved.
The first would be a more type guess based aproach like the following:

static readonly metadata: MetadataOptions = {
	properties: {
		someFunc: {
			type: "(button: sap.m.Button) => void"
		}
	}
};

// the .gen.d.ts would look like this:
import { $ControlSettings } from "sap/ui/core/Control";
import Button from "sap/m/Button";

declare module "./Example" {
	interface $ExampleSettings extends $ControlSettings {
		callback?: (button: Button) => void
	}
	// ... //
}

The idea is to define them as type-safe TS types and convert them to the simple type with the transformation to js.
In the case of the example, the metadata would be rewritten to type: "function".

Alternatively, if guessing the type would be too difficult, since some object types can be very complex, enhancing the property with an additional key could make it easier and enable the useage of interfaces and named types:

static readonly metadata: MetadataOptions = {
	properties: {
		someFunc: {
			tsType: "(button: sap.m.Button) => void",
			type: "function"
		}
	}
};

This 2nd approach would also .

Here the tsType would be used for the gen.d.ts file and removed in the js transformation as it's not needed anymore.

It's not often that i need to use these property types but when I do, it's follow by unnessecary assertion of types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant