Skip to content

Can not derive model properties #9727

@dvv

Description

@dvv

Describe the bug

Hello!

I'm struggling with the following piece of tsp:

model Object {
  @visibility(Lifecycle.Read)
  @key id: string,
}

model Item extends Object {
  name: string,
  // other props...
}

@doc("An excerpt of Item for Account")
model Account_Item is PickProperties<Item, "id" | "name">;

model Account extends Object {

  @visibility(Lifecycle.Read)
  item: Account_Item,
  // item: PickProperties<Item, "id" | "name">,

  @visibility(Lifecycle.Create, Lifecycle.Update)
  // item_id: Account_Item.id, // <------------ ERR: Model doesn't have member id
  item_id: Item.id,                   // <------------ ERR: Duplicate type name: 'Account'

}

// below should go definitions using Create<Account>, Update<Account> hence lifecycles.

Both kinds of definition of item_id seem to be evident to me, but they result in throwing errors (see comments).
Both errors seem a bit inadequate to me, esp. "Duplicate type name: 'Account'".

Am I doing something fundamentally wrong?
How else to express a model property that is an id of another model and must be visible at create/update lifecycle only?

TIA

Reproduction

model Object {
  @visibility(Lifecycle.Read)
  @key id: string,
}

model Item extends Object {
  name: string,
  // other props...
}

@doc("An excerpt of Item for Account")
model Account_Item is PickProperties<Item, "id" | "name">;

model Account extends Object {

  @visibility(Lifecycle.Read)
  item: Account_Item,
  // item: PickProperties<Item, "id" | "name">,

  @visibility(Lifecycle.Create, Lifecycle.Update)
  // item_id: Account_Item.id, // <------------ ERR: Model doesn't have member id
  item_id: Item.id,                   // <------------ ERR: Duplicate type name: 'Account'

}

// below should go definitions using Create<Account>, Update<Account> hence lifecycles.

Checklist

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions