I am trying to write a function where I would like to indicate that it returns some simple JavaScript object. The signature of the object is unknown and not yet interesting, only the fact that it is a simple object. I mean a simple object that satisfies, for example, jQuery functions isPlainObject. for instance
{ a: 1, b: "b" }
is a simple object but
var obj = new MyClass();
is not a "simple" object, since it is constructornot Object. jQuery does some more precise work in $.isPlainObject, but that is beyond the scope of the question.
If I try to use a type Object, it will be compatible with any custom object, since they are inherited from Object.
Is there a way to set the type of a “simple object” in TypeScript?
, , .
var obj: PlainObject = { a: 1 };
var obj2: PlainObject = new MyClass();
, . ASP.NET MVC-.
export class MyController {
...
static GetResult(id: number): JQueryPromise<PlainObject> {
return $.post("mycontroller/getresult", ...);
}
...
}
, , - .
export class MyViewModelClass {
...
LoadResult(id: number): JQueryPromise<MyControllerResult> {
return MyController.GetResult(id).then(plainResult => new MyControllerResult(plainResult));
}
...
}
, JQueryPromise<any> JQueryPromise<Object>. , done then. , viewmodel , .
PlainObject, , , PlainObject MyControllerResult, - .