How to set the type of idProp?
fineup opened this issue · comments
fine commented
After customizing the id according to the method of Setting an ID property, the similar default returned under typescript is string. How to specify the type, such as Custom-${string}
Javier Gonzalez commented
idProp.typedAs<T>()
added in v1.1.0
unit test
test("idProp.typedAs", () => {
type Id = `custom-${string}`
@testModel("M")
class M extends Model({
id: idProp.typedAs<Id>(),
}) {}
const m = new M({ id: "custom-1" })
assert(m.id, _ as Id)
assert(_ as SnapshotInOf<M>["id"], _ as Id | undefined)
assert(_ as SnapshotOutOf<M>["id"], _ as Id)
assert(m.$modelId, _ as Id)
})
Javier Gonzalez commented
Closing since it now should be supported as shown above.