The `ModelObject<this>` type lose properties.
See original GitHub issuetype NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
type ModelObject<T extends object> = {
[K in Exclude<NonFunctionPropertyNames<T>, 'model'>]: T[K];
};
class User {
id!: number;
name!: string;
avatar!: string;
toJson () {
const rs: ModelObject<this> = 0 as any;
return rs;
}
getName () {
const json = this.toJson();
return json.name; // Property 'name' does not exist on type 'ModelObject<this>'.
}
}
type UserJson = NonFunctionPropertyNames<User>; // output type UserJson = "id" | "name" | "avatar"
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:6
Top Results From Across the Web
Issue with generic properties when type mapping
I believe the cause for this is that T is generic without any type restrictions/narrowing being applied to it, and therefore the type...
Read more >Properties defined on ObservableObject are lost when ...
I am using Typescript to define objects that extend the kendo.data.ObservableObject type. These objects contain getter and setter properties ...
Read more >Model Objects Properties | Advance Steel 2021
A model object is defined by the object type (e.g. Beam), model role ... It can be moved to another group using the...
Read more >Managing model data in your app - Apple Developer
A property wrapper type that subscribes to an observable object and invalidates a view whenever the observable object changes.
Read more >I/O Model Object Types - inmation Docs!
If all referenced items have a Bad object state then the setting of the BadStatePriority property will determine which of the referenced items...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Experiencing this.
“typescript”: “4.1.5” “objection”: “2.2.14”
Ok. I think this is a bug introduced by typescript 4. Objection’s tests still use 3.9.something. Typescrip 4 probably changed how the
this
type is handled in some cases.