You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Working with the latest mst (0.10.0) and liking it a lot, but we're experiencing some trouble with inferring the return type of getSnapshot, specifically when the model is instantiated in another scope. Say we have a model:
If we create an instance and get a snapshot in the same scope, it's able to infer that getSnapshot returns an object that includes the property "testing":
const myInstance = MyModel.create({ testing: "1,2,3" });
const mySnapshot = getSnapshot(myInstance).testing //ok --testing is a known property
However, if we're creating/assigning the instance at a later time (for example, in tests):
describe("test", function() {
let myInstance: typeof MyModel.Type
before(function() {
myInstance = MyModel.create({ testing: "1,2,3" });
})
it("ts compile error", function() {
const mySnapshot = getSnapshot(myInstance).testing //not ok -- inferred type of mySnapshot is {}
})
});
There's an easy solution, ie by explicitly telling it the return type (getSnapshot<typeof MyModel.Type>...), but I'd assumed it would be able to infer the type in this case.
The text was updated successfully, but these errors were encountered:
djres88
changed the title
Inferred type of
Inferred type of getSnapshot
Aug 17, 2017
Each model has two properties: Type and SnapshotType; due to TS lack of mapped conditional type we can't do much and always infer correctly, waiting for #117 :)
Working with the latest mst (0.10.0) and liking it a lot, but we're experiencing some trouble with inferring the return type of getSnapshot, specifically when the model is instantiated in another scope. Say we have a model:
If we create an instance and get a snapshot in the same scope, it's able to infer that getSnapshot returns an object that includes the property "testing":
However, if we're creating/assigning the instance at a later time (for example, in tests):
There's an easy solution, ie by explicitly telling it the return type (
getSnapshot<typeof MyModel.Type>...
), but I'd assumed it would be able to infer the type in this case.The text was updated successfully, but these errors were encountered: