-
Notifications
You must be signed in to change notification settings - Fork 636
Fix to typedefs for Typescript 2.7 #637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,7 +191,7 @@ export class ModelType<S, T> extends ComplexType<S, T> implements IModelType<S, | |
|
|
||
| props<SP, TP>( | ||
| properties: { [K in keyof TP]: IType<any, TP[K]> } & { [K in keyof SP]: IType<SP[K], any> } | ||
| ): IModelType<S & SP, T & TP> { | ||
| ): IModelType<S & SP & Snapshot<SP>, T & TP> { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Solution from #635
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea why,
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (done in latest commit)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mweststrate wdys?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have the impression that property types are broken completely with TS 2.7, are you guys experiencing the same? I mean even
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have the impression that property types are broken completely with TS 2.7, are you guys experiencing the same? I mean even
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mweststrate type IModelProperties<T> = { [K in keyof T]: T[K] };
function inferer<T>(properties: IModelProperties<T>): IModelProperties<T> {
return properties;
}
// if you hover a you will see that prop1 and prop2 are:
// inferred as any on typescript 2.7.1
// inferred as string and number on typescript 2.6.2
const a = inferer({
prop1: "asd",
prop2: 1,
});
type IMGOODTYPE = IModelProperties<{ a: string }>;
// but here, the original type of prop1 and prop2 are restored,
// even in typescript 2.7.1
type imgoodTYPEEevenahasbadone = typeof a; |
||
| return this.cloneAndEnhance({ properties } as any) | ||
| } | ||
|
|
||
|
|
@@ -457,7 +457,7 @@ export interface IModelType<S, T> extends IComplexType<S, T & IStateTreeNode> { | |
| props: { [K in keyof TP]: IType<any, TP[K]> | TP[K] } & | ||
| { [K in keyof SP]: IType<SP[K], any> | SP[K] } | ||
| ): IModelType<S & Snapshot<SP>, T & TP> | ||
| //props<P>(props: IModelProperties<P>): IModelType<S & Snapshot<P>, T & P> | ||
| props<P>(props: IModelProperties<P>): IModelType<S & Snapshot<P>, T & P> | ||
| views<V extends Object>(fn: (self: T & IStateTreeNode) => V): IModelType<S, T & V> | ||
| actions<A extends { [name: string]: Function }>( | ||
| fn: (self: T & IStateTreeNode) => A | ||
|
|
@@ -480,11 +480,12 @@ export type Snapshot<T> = { | |
| [K in keyof T]?: Snapshot<T[K]> | any // Any because we cannot express conditional types yet, so this escape is needed for refs and such.... | ||
| } | ||
|
|
||
| export function model<T = {}>(): IModelType<T | Snapshot<T>, T> | ||
| export function model<T = {}>(properties: IModelProperties<T>): IModelType<Snapshot<T>, T> | ||
| export function model<T = {}>( | ||
| name: string, | ||
| properties?: IModelProperties<T> | ||
| ): IModelType<Snapshot<T>, T> | ||
| export function model<T = {}>(properties?: IModelProperties<T>): IModelType<Snapshot<T>, T> | ||
| properties: IModelProperties<T> | ||
| ): IModelType<T | Snapshot<T>, T> | ||
| /** | ||
| * Creates a new model type by providing a name, properties, volatile state and actions. | ||
| * | ||
|
|
@@ -493,10 +494,11 @@ export function model<T = {}>(properties?: IModelProperties<T>): IModelType<Snap | |
| * @export | ||
| * @alias types.model | ||
| */ | ||
| export function model(...args: any[]) { | ||
| const name = typeof args[0] === "string" ? args.shift() : "AnonymousModel" | ||
| export function model<T = {}>(...args: any[]): IModelType<Snapshot<any>, any> { | ||
| const name = typeof args[0] === "string" ? args.shift() as string : "AnonymousModel" | ||
| const properties = args.shift() || {} | ||
| return new ModelType({ name, properties }) | ||
| const config = { name: name as string, properties } as ModelTypeConfig | ||
| return new ModelType(config) | ||
| } | ||
|
|
||
| export function compose<T1, S1, T2, S2, T3, S3>( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a yarn project,
You'll need to upgrade via yarn for the lock file to be updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(done in latest commit)