-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
enhancementNew feature or requestNew feature or request
Description
The new form could provide better refactoring possibilities with class names in string quotes only in class definition place,
not in instancing places anymore, because custom classes extended from Ext classes will be class definitions, not interface definitions anymore. But Statics insterfaces must be changed into type definitions:
// test definitions:
declare namespace Ext.Test {
class TestClass {
static $className?: string;
$className?: string;
constructor (cfg: Ext.Test.TestClass.Cfg);
statics?: Ext.Test.TestClass.Statics;
}
interface StaticsBase {
BASE_PROP?: string;
[propertyName: string]: any;
}
}
declare namespace Ext.Test.Other {
interface Statics extends Ext.Test.StaticsBase {
OTHER_PROP?: string;
}
}
declare namespace Ext.Test.Another {
interface Statics extends Ext.Test.StaticsBase {
ANOTHER_PROP?: string;
}
}
declare namespace Ext.Test.TestClass {
type Statics = (
(() => Ext.Test.Other.Statics & Ext.Test.Another.Statics) &
(Ext.Test.Other.Statics & Ext.Test.Another.Statics)
);
interface Def {
extends?: string;
statics?: Ext.Test.TestClass.Statics;
}
interface Cfg {
base?: string;
other?: string;
another?: string;
}
}
// MyInstance.ts
declare namespace My.Custom.Namespace {
class MyInstance extends Ext.Test.TestClass {
static MyPublicStaticMethod (): void;
other?: string;
MyPublicInstanceMethod? (): void; // to declare '?' means it's not necessary to override in extended class
}
}
Ext.define(
'My.Custom.Namespace.MyInstance',
<My.Custom.Namespace.MyInstance & Ext.Test.TestClass.Def>{
statics: <Ext.Test.TestClass.Statics & typeof My.Custom.Namespace.MyInstance>{ // this is necessary to define in `<>` !!!
MyPublicStaticMethod: () => {
console.log("My.Custom.Namespace.MyInstance.MyPublicStaticMethod()");
},
OTHER_PROP: 'other_default'
},
constructor: function (cfg: Ext.Test.TestClass.Cfg) {
this.other = cfg.other;
},
MyPublicInstanceMethod: function () {
var otherDefault = this.statics().OTHER_PROP;
console.log(this.other, otherDefault);
}
}
);
// my extended instance:
declare namespace My.Custom.Namespace.MyInstance {
class Extended extends My.Custom.Namespace.MyInstance {
static MyPublicStaticMethodExtended? (): void;
otherExtended?: string;
MyPublicInstanceMethodExtended (): void;
}
}
Ext.define(
'My.Custom.Namespace.MyInstance.Extended',
<My.Custom.Namespace.MyInstance.Extended & Ext.Base.Def>{
extend: My.Custom.Namespace.MyInstance.$className,
statics: <Ext.Test.TestClass.Statics & typeof My.Custom.Namespace.MyInstance.Extended>{ // this is necessary to define in `<>` !!!
MyPublicStaticMethodExtended: () => {
console.log("My.Custom.Namespace.MyInstance.Extended.MyPublicStaticMethod");
},
ANOTHER_PROP: 'another_default'
},
constructor: function (cfg: Ext.Test.TestClass.Cfg) {
this.other = cfg.other;
},
MyPublicInstanceMethodExtended: function () {
var another = this.statics().ANOTHER_PROP;
console.log(this.other, another);
}
}
);
// creating instances:
var testInstance1 = Ext.create(
My.Custom.Namespace.MyInstance.$className,
<Ext.Test.TestClass.Cfg>{
other: 'other1'
}
) as My.Custom.Namespace.MyInstance;
testInstance1.MyPublicInstanceMethod();
var testInstanceExtended = new My.Custom.Namespace.MyInstance.Extended(
<Ext.Test.TestClass.Cfg>{
another: 'another2'
}
);
testInstanceExtended.MyPublicInstanceMethodExtended();
My.Custom.Namespace.MyInstance.MyPublicStaticMethod();
My.Custom.Namespace.MyInstance.Extended.MyPublicStaticMethod();
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request