Pass by parameter a class with type assertion - Typescript
I'm simulating a multiple inheritance in typescript by this way:
export const FileManager = superClass => class extends superClass {
//...
}
export declare abstract class Model<T extends Model<T>>{
//...
}
I tried the following and then it says that FileManager was expecting 1 parameter instead of 2.
export class Order extends FileManager(Model<Order>)){
//...
}
So I changed the FileManager definition to:
export const FileManager = (superClass,t) => class extends superClass<t> {
//...
}
But then I get this error:
[ts] Value of type 'typeof Model' is not callable. Did you mean to
include 'new'?
It was working well before I needed to declare the Type Assertion to model class (its neccesary, I cant remove it).
I think the problem is the way I receive the 'typeof' as parameter and how to instantiate dynamically.
Im really stuck, I will be very grateful to any help
javascript typescript factory type-assertion
|
show 1 more comment
I'm simulating a multiple inheritance in typescript by this way:
export const FileManager = superClass => class extends superClass {
//...
}
export declare abstract class Model<T extends Model<T>>{
//...
}
I tried the following and then it says that FileManager was expecting 1 parameter instead of 2.
export class Order extends FileManager(Model<Order>)){
//...
}
So I changed the FileManager definition to:
export const FileManager = (superClass,t) => class extends superClass<t> {
//...
}
But then I get this error:
[ts] Value of type 'typeof Model' is not callable. Did you mean to
include 'new'?
It was working well before I needed to declare the Type Assertion to model class (its neccesary, I cant remove it).
I think the problem is the way I receive the 'typeof' as parameter and how to instantiate dynamically.
Im really stuck, I will be very grateful to any help
javascript typescript factory type-assertion
TheTinModelis it always the same as the derived class ? What do you need it for ? Are you sure polymorphicthiswould not be a better fit ? Getting the mixin to work we can do, getting it to work with a generic class we can work around some limitations and we can do it. But the part that has the class referencing the class itself in it's extends expression clause is an issue I have not been able to figure out.
– Titian Cernicova-Dragomir
Nov 26 '18 at 21:11
But why try to figure it out? When placing a language decoration facade (typescript) on top of a built-in language facade (Class) one must expect that strange inconsistencies will occur. The object hierarchy is interesting too. TheFilemanagermethods are accessed directly by theOrder? I bet not.
– Randy Casburn
Nov 26 '18 at 21:14
@RandyCasburn Surprisingly yes! Order can access both attributes and methods as if their were own. The reason I decided to do this is that I found that there is no easy alternative to multiple inheritance that let you use base and super method (unlike mixins). I unsderstand that its prone to errors, but im trying my best
– user3294339
Nov 27 '18 at 14:18
@TitianCernicova-Dragomir Im using a library to implement typescript + sequelize and it defines a generic model in order to extend from it your classes and be able to use the ORM annotations
– user3294339
Nov 27 '18 at 14:26
JavaScript is not a multiple inheritance language...you are attempting to work around the design of the language. You should concentrate on using the language the way it is designed to be used. Just because you can put a Kludge together doesn't mean you should. I know you can access them through the inheritance chain - that was not my point. The point was that your inheritance hierarchy is a kludge.
– Randy Casburn
Nov 27 '18 at 14:27
|
show 1 more comment
I'm simulating a multiple inheritance in typescript by this way:
export const FileManager = superClass => class extends superClass {
//...
}
export declare abstract class Model<T extends Model<T>>{
//...
}
I tried the following and then it says that FileManager was expecting 1 parameter instead of 2.
export class Order extends FileManager(Model<Order>)){
//...
}
So I changed the FileManager definition to:
export const FileManager = (superClass,t) => class extends superClass<t> {
//...
}
But then I get this error:
[ts] Value of type 'typeof Model' is not callable. Did you mean to
include 'new'?
It was working well before I needed to declare the Type Assertion to model class (its neccesary, I cant remove it).
I think the problem is the way I receive the 'typeof' as parameter and how to instantiate dynamically.
Im really stuck, I will be very grateful to any help
javascript typescript factory type-assertion
I'm simulating a multiple inheritance in typescript by this way:
export const FileManager = superClass => class extends superClass {
//...
}
export declare abstract class Model<T extends Model<T>>{
//...
}
I tried the following and then it says that FileManager was expecting 1 parameter instead of 2.
export class Order extends FileManager(Model<Order>)){
//...
}
So I changed the FileManager definition to:
export const FileManager = (superClass,t) => class extends superClass<t> {
//...
}
But then I get this error:
[ts] Value of type 'typeof Model' is not callable. Did you mean to
include 'new'?
It was working well before I needed to declare the Type Assertion to model class (its neccesary, I cant remove it).
I think the problem is the way I receive the 'typeof' as parameter and how to instantiate dynamically.
Im really stuck, I will be very grateful to any help
javascript typescript factory type-assertion
javascript typescript factory type-assertion
asked Nov 26 '18 at 21:00
user3294339user3294339
135
135
TheTinModelis it always the same as the derived class ? What do you need it for ? Are you sure polymorphicthiswould not be a better fit ? Getting the mixin to work we can do, getting it to work with a generic class we can work around some limitations and we can do it. But the part that has the class referencing the class itself in it's extends expression clause is an issue I have not been able to figure out.
– Titian Cernicova-Dragomir
Nov 26 '18 at 21:11
But why try to figure it out? When placing a language decoration facade (typescript) on top of a built-in language facade (Class) one must expect that strange inconsistencies will occur. The object hierarchy is interesting too. TheFilemanagermethods are accessed directly by theOrder? I bet not.
– Randy Casburn
Nov 26 '18 at 21:14
@RandyCasburn Surprisingly yes! Order can access both attributes and methods as if their were own. The reason I decided to do this is that I found that there is no easy alternative to multiple inheritance that let you use base and super method (unlike mixins). I unsderstand that its prone to errors, but im trying my best
– user3294339
Nov 27 '18 at 14:18
@TitianCernicova-Dragomir Im using a library to implement typescript + sequelize and it defines a generic model in order to extend from it your classes and be able to use the ORM annotations
– user3294339
Nov 27 '18 at 14:26
JavaScript is not a multiple inheritance language...you are attempting to work around the design of the language. You should concentrate on using the language the way it is designed to be used. Just because you can put a Kludge together doesn't mean you should. I know you can access them through the inheritance chain - that was not my point. The point was that your inheritance hierarchy is a kludge.
– Randy Casburn
Nov 27 '18 at 14:27
|
show 1 more comment
TheTinModelis it always the same as the derived class ? What do you need it for ? Are you sure polymorphicthiswould not be a better fit ? Getting the mixin to work we can do, getting it to work with a generic class we can work around some limitations and we can do it. But the part that has the class referencing the class itself in it's extends expression clause is an issue I have not been able to figure out.
– Titian Cernicova-Dragomir
Nov 26 '18 at 21:11
But why try to figure it out? When placing a language decoration facade (typescript) on top of a built-in language facade (Class) one must expect that strange inconsistencies will occur. The object hierarchy is interesting too. TheFilemanagermethods are accessed directly by theOrder? I bet not.
– Randy Casburn
Nov 26 '18 at 21:14
@RandyCasburn Surprisingly yes! Order can access both attributes and methods as if their were own. The reason I decided to do this is that I found that there is no easy alternative to multiple inheritance that let you use base and super method (unlike mixins). I unsderstand that its prone to errors, but im trying my best
– user3294339
Nov 27 '18 at 14:18
@TitianCernicova-Dragomir Im using a library to implement typescript + sequelize and it defines a generic model in order to extend from it your classes and be able to use the ORM annotations
– user3294339
Nov 27 '18 at 14:26
JavaScript is not a multiple inheritance language...you are attempting to work around the design of the language. You should concentrate on using the language the way it is designed to be used. Just because you can put a Kludge together doesn't mean you should. I know you can access them through the inheritance chain - that was not my point. The point was that your inheritance hierarchy is a kludge.
– Randy Casburn
Nov 27 '18 at 14:27
The
T in Model is it always the same as the derived class ? What do you need it for ? Are you sure polymorphic this would not be a better fit ? Getting the mixin to work we can do, getting it to work with a generic class we can work around some limitations and we can do it. But the part that has the class referencing the class itself in it's extends expression clause is an issue I have not been able to figure out.– Titian Cernicova-Dragomir
Nov 26 '18 at 21:11
The
T in Model is it always the same as the derived class ? What do you need it for ? Are you sure polymorphic this would not be a better fit ? Getting the mixin to work we can do, getting it to work with a generic class we can work around some limitations and we can do it. But the part that has the class referencing the class itself in it's extends expression clause is an issue I have not been able to figure out.– Titian Cernicova-Dragomir
Nov 26 '18 at 21:11
But why try to figure it out? When placing a language decoration facade (typescript) on top of a built-in language facade (Class) one must expect that strange inconsistencies will occur. The object hierarchy is interesting too. The
Filemanager methods are accessed directly by the Order? I bet not.– Randy Casburn
Nov 26 '18 at 21:14
But why try to figure it out? When placing a language decoration facade (typescript) on top of a built-in language facade (Class) one must expect that strange inconsistencies will occur. The object hierarchy is interesting too. The
Filemanager methods are accessed directly by the Order? I bet not.– Randy Casburn
Nov 26 '18 at 21:14
@RandyCasburn Surprisingly yes! Order can access both attributes and methods as if their were own. The reason I decided to do this is that I found that there is no easy alternative to multiple inheritance that let you use base and super method (unlike mixins). I unsderstand that its prone to errors, but im trying my best
– user3294339
Nov 27 '18 at 14:18
@RandyCasburn Surprisingly yes! Order can access both attributes and methods as if their were own. The reason I decided to do this is that I found that there is no easy alternative to multiple inheritance that let you use base and super method (unlike mixins). I unsderstand that its prone to errors, but im trying my best
– user3294339
Nov 27 '18 at 14:18
@TitianCernicova-Dragomir Im using a library to implement typescript + sequelize and it defines a generic model in order to extend from it your classes and be able to use the ORM annotations
– user3294339
Nov 27 '18 at 14:26
@TitianCernicova-Dragomir Im using a library to implement typescript + sequelize and it defines a generic model in order to extend from it your classes and be able to use the ORM annotations
– user3294339
Nov 27 '18 at 14:26
JavaScript is not a multiple inheritance language...you are attempting to work around the design of the language. You should concentrate on using the language the way it is designed to be used. Just because you can put a Kludge together doesn't mean you should. I know you can access them through the inheritance chain - that was not my point. The point was that your inheritance hierarchy is a kludge.
– Randy Casburn
Nov 27 '18 at 14:27
JavaScript is not a multiple inheritance language...you are attempting to work around the design of the language. You should concentrate on using the language the way it is designed to be used. Just because you can put a Kludge together doesn't mean you should. I know you can access them through the inheritance chain - that was not my point. The point was that your inheritance hierarchy is a kludge.
– Randy Casburn
Nov 27 '18 at 14:27
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53488996%2fpass-by-parameter-a-class-with-type-assertion-typescript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53488996%2fpass-by-parameter-a-class-with-type-assertion-typescript%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The
TinModelis it always the same as the derived class ? What do you need it for ? Are you sure polymorphicthiswould not be a better fit ? Getting the mixin to work we can do, getting it to work with a generic class we can work around some limitations and we can do it. But the part that has the class referencing the class itself in it's extends expression clause is an issue I have not been able to figure out.– Titian Cernicova-Dragomir
Nov 26 '18 at 21:11
But why try to figure it out? When placing a language decoration facade (typescript) on top of a built-in language facade (Class) one must expect that strange inconsistencies will occur. The object hierarchy is interesting too. The
Filemanagermethods are accessed directly by theOrder? I bet not.– Randy Casburn
Nov 26 '18 at 21:14
@RandyCasburn Surprisingly yes! Order can access both attributes and methods as if their were own. The reason I decided to do this is that I found that there is no easy alternative to multiple inheritance that let you use base and super method (unlike mixins). I unsderstand that its prone to errors, but im trying my best
– user3294339
Nov 27 '18 at 14:18
@TitianCernicova-Dragomir Im using a library to implement typescript + sequelize and it defines a generic model in order to extend from it your classes and be able to use the ORM annotations
– user3294339
Nov 27 '18 at 14:26
JavaScript is not a multiple inheritance language...you are attempting to work around the design of the language. You should concentrate on using the language the way it is designed to be used. Just because you can put a Kludge together doesn't mean you should. I know you can access them through the inheritance chain - that was not my point. The point was that your inheritance hierarchy is a kludge.
– Randy Casburn
Nov 27 '18 at 14:27