refactor: add better types to field configs (#6317)

* fix: add config types in all fields

* fix: add interfaces to fromJson

* chore: cleanup from cherry-pick

* chore: add docs to exported properties

* chore: format

* chore: remove unnecessary test case

* fix: replacing message references in tooltip

* chore: fix format

* chore: rename interfaces to be more explicit

* chore: format

* fix: add proper visibility keywords

* chore: fix label field config name

* chore: formatting

* chore: remove unnecessarily renamed imports
This commit is contained in:
Beka Westberg
2022-08-08 18:16:50 +00:00
committed by GitHub
parent 8f4b49a771
commit f07b06b6d5
13 changed files with 286 additions and 123 deletions

View File

@@ -19,7 +19,7 @@
import * as goog from '../closure/goog/goog.js';
goog.declareModuleId('Blockly.FieldLabelSerializable');
import {FieldLabel} from './field_label.js';
import {FieldLabelConfig, FieldLabelFromJsonConfig, FieldLabel} from './field_label.js';
import * as fieldRegistry from './field_registry.js';
import * as parsing from './utils/parsing.js';
@@ -52,7 +52,7 @@ export class FieldLabelSerializable extends FieldLabel {
* for a list of properties this parameter supports.
*/
constructor(
opt_value?: string, opt_class?: string, opt_config?: AnyDuringMigration) {
opt_value?: string, opt_class?: string, opt_config?: FieldLabelConfig) {
super(String(opt_value ?? ''), opt_class, opt_config);
}
@@ -64,9 +64,9 @@ export class FieldLabelSerializable extends FieldLabel {
* @nocollapse
* @internal
*/
static override fromJson(options: AnyDuringMigration):
static override fromJson(options: FieldLabelFromJsonConfig):
FieldLabelSerializable {
const text = parsing.replaceMessageReferences(options['text']);
const text = parsing.replaceMessageReferences(options.text);
// `this` might be a subclass of FieldLabelSerializable if that class
// doesn't override the static fromJson method.
return new this(text, undefined, options);