@@ -121,7 +121,7 @@ export class ModelType<S, T> extends ComplexType<S, T> implements IModelType<S,
121121 * The original object definition
122122 */
123123 public readonly initializers : ( ( instance : any ) => any ) [ ]
124- public readonly properties : { [ K : string ] : IType < any , any > }
124+ public readonly properties : { [ K : string ] : IType < any , any > } = { }
125125 private preProcessor : ( snapshot : any ) => any | undefined
126126 private readonly propertiesNames : string [ ]
127127
@@ -190,7 +190,8 @@ export class ModelType<S, T> extends ComplexType<S, T> implements IModelType<S,
190190 }
191191
192192 props < SP , TP > (
193- properties : { [ K in keyof TP ] : IType < any , TP [ K ] > } & { [ K in keyof SP ] : IType < SP [ K ] , any > }
193+ properties : { [ K in keyof TP ] : IType < any , TP [ K ] > | TP [ K ] } &
194+ { [ K in keyof SP ] : IType < SP [ K ] , any > | SP [ K ] }
194195 ) : IModelType < S & SP , T & TP > {
195196 return this . cloneAndEnhance ( { properties } as any )
196197 }
@@ -309,15 +310,16 @@ export class ModelType<S, T> extends ComplexType<S, T> implements IModelType<S,
309310 return instance as Object
310311 }
311312
312- finalizeNewInstance = ( node : ObjectNode , snapshot : any ) => {
313- const instance = node . storedValue as IStateTreeNode
313+ finalizeNewInstance = ( node : INode , snapshot : any ) => {
314+ const objNode = node as ObjectNode
315+ const instance = objNode . storedValue as IStateTreeNode
314316 this . forAllProps ( ( name , type ) => {
315317 extendShallowObservable ( instance , {
316318 [ name ] : observable . ref (
317- type . instantiate ( node , name , node . _environment , snapshot [ name ] )
319+ type . instantiate ( objNode , name , objNode . _environment , snapshot [ name ] )
318320 )
319321 } )
320- extras . interceptReads ( instance , name , node . unbox )
322+ extras . interceptReads ( instance , name , objNode . unbox )
321323 } )
322324
323325 this . initializers . reduce ( ( self , fn ) => fn ( self ) , instance )
@@ -493,10 +495,10 @@ export function model<T = {}>(properties?: IModelProperties<T>): IModelType<Snap
493495 * @export
494496 * @alias types.model
495497 */
496- export function model ( ...args : any [ ] ) {
498+ export function model < T = { } > ( ...args : any [ ] ) : IModelType < Snapshot < T > , T > {
497499 const name = typeof args [ 0 ] === "string" ? args . shift ( ) : "AnonymousModel"
498500 const properties = args . shift ( ) || { }
499- return new ModelType ( { name, properties } )
501+ return new ModelType ( { name, properties } ) as IModelType < Snapshot < T > , T >
500502}
501503
502504export function compose < T1 , S1 , T2 , S2 , T3 , S3 > (
0 commit comments