Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

Draft PR description (changes not applied yet): The current useProperties() typing cannot express per-key value types, which prevents SignalReader inference from a key→type map. This update refines the API to align with useProperty’s generic usage.

  • Types: Extend useProperties generics to accept a key→type map and return SignalReader<T | undefined> per key without any.
  • Docs: Update the Shadow Objects API and best-practices examples to show typed useProperties.
  • Tests: Add kernel coverage for typed useProperties usage.
const { foo, bar } = useProperties<{ foo: number; bar: string }>({
  foo: "prop.name.foo",
  bar: "prop.bar",
})

foo // SignalReader<number | undefined>
bar // SignalReader<string | undefined>
Original prompt

This section details on the original issue you should resolve

<issue_title>improve type types for useProperties() from ShadowObjectCreationAPI</issue_title>
<issue_description>erweitere die type definitions von useProperties()aus der ShadowObjectCreationAPI

es soll folgendes möglich sein:

const { foo, bar } = useProperties<{foo: number, bar: string}>({foo: "prop.name.foo", bar: "prop.bar"})

foo // ist vom type SignalReader<number | undefined>
bar // ist vom type SignalReader<string | undefined>

die setProperties function soll als optionales type argument eine map mit den key -> type mappings bekommen.

das soll analog zu der vorhanden type definition von useProperty funktionieren: const foo = useProperty<number)('prop.name.foo')
</issue_description>

<agent_instructions>update entsprechend auch die stellen aus der developer documentation wo diese methode verwendet wird. update auch das CHANGELOG und schreibe test cases dafür (oder passe bestehende an)</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Improve type definitions for useProperties() in ShadowObjectCreationAPI Improve useProperties typing for key→type maps Jan 20, 2026
Copilot AI requested a review from spearwolf January 20, 2026 09:55
@spearwolf
Copy link
Owner

@copilot bitte mache das beispiel aus dem issue möglich und verwende nicht einen any type

Co-authored-by: spearwolf <12805+spearwolf@users.noreply.github.com>
Comment on lines +128 to +129
this.viewComponent.setProperty('x', this.x);
this.viewComponent.setProperty('y', this.y);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert changes - the use of setProperties() and setProperty() should not change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the view-components doc example to use setProperties again as requested. Commit: ad9339d.

Comment on lines +121 to +122
this.viewComponent.setProperty('x', this.x);
this.viewComponent.setProperty('y', this.y);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert changes - the use of setProperties() and setProperty() should not change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the second setProperties example in the view-components doc. Commit: ad9339d.

Comment on lines +18 to +20
const { userId } = useProperties<{userId: string}>({
userId: 'userId',
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert changes - do not use setProprties() with a single property. thats for setProperty

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted the guide example back to useProperty instead of setProperties for a single field. Commit: ad9339d.

@spearwolf spearwolf marked this pull request as ready for review January 20, 2026 11:05
Copilot AI review requested due to automatic review settings January 20, 2026 11:05
Copilot AI requested a review from spearwolf January 20, 2026 11:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refines useProperties() TypeScript typing to support per-key value types via a key→type map, aligning its inference behavior with useProperty, and updates docs/tests accordingly.

Changes:

  • Update ShadowObjectCreationAPI.useProperties to accept a key→type map generic and return SignalReader<T[K] | undefined> per key (no any).
  • Align kernel implementation typing (useProperty/useProperties) with Maybe<T> return types and reduce any usage.
  • Update documentation examples and add a kernel spec covering typed useProperties usage.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/shadow-objects/src/types.ts Updates useProperties API typing to support key→type maps.
packages/shadow-objects/src/in-the-dark/Kernel.ts Aligns useProperty return type with Maybe<T> and implements typed useProperties return shape.
packages/shadow-objects/src/in-the-dark/Kernel.spec.ts Adds a spec exercising typed useProperties usage.
packages/shadow-objects/docs/04-patterns/best-practices.md Updates example to show typed useProperties.
packages/shadow-objects/docs/03-api/03-view-components.md Fixes docs to use setProperty (instead of non-existent setProperties).
packages/shadow-objects/docs/03-api/01-shadow-object-api.md Updates useProperties signature/example to reflect typed key maps.
packages/shadow-objects/docs/02-guides/02-creating-shadow-objects.md Updates guide example to use typed useProperties.
packages/shadow-objects/CHANGELOG.md Adds an Unreleased changelog entry for the typing improvement.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +42 to 43
* **Signature:** `useProperties<T>(map: { [K in keyof T]: string }): { [K in keyof T]: () => T[K] | undefined }`
* **Returns:** An object where keys match the input map, and values are signal readers.
Copy link

Copilot AI Jan 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

useProperty is documented above as returning () => T, but the actual API type is SignalReader<Maybe<T>> (i.e., T | undefined for consumers with strictNullChecks). Since useProperties is now documented as returning T[K] | undefined, please update the useProperty signature (and ideally its example text) to also reflect the possible undefined value for consistency and correctness.

Copilot uses AI. Check for mistakes.
@spearwolf spearwolf closed this Jan 20, 2026
@spearwolf
Copy link
Owner

nada

@spearwolf spearwolf deleted the copilot/improve-useproperties-type-definitions branch January 20, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

improve type types for useProperties() from ShadowObjectCreationAPI

2 participants