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

Abierto
#406 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
typescript
Área
tooling

Línea de trabajo

Start by reviewing the MetadataOptions property definitions and the transformation that produces JavaScript and .gen.d.ts files. Compare the proposed type-guessing and tsType approaches, then determine how specific function and object types should be represented in generated declarations while remaining simple at runtime. Done means the chosen approach is defined and supported consistently.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
213
Forks
35
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de UI5/typescript

Todos los issues de UI5/typescript

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.