Repository navigation
Conversation
`get<T = any>(path): T` lets TypeScript infer `T` from the call site, so `expect(model.get(path))` with an overloaded `expect` (such as an accessibility matcher augmentation) infers `T` from the first overload and picks it, failing with TS2339 on the Jasmine matcher. Add a non-generic `get(path): any` overload ahead of `get<T>(path): T`. An untyped call resolves to `any`, which overload resolution does not treat as a subtype of the other overload parameter, and `get<string>(path)` still returns `string`. Fixes a2ui-project#3784
There was a problem hiding this comment.
Code Review
This pull request updates DataModel.get(path) in typescript/core/web_core/src/state/data-model.ts by adding overloads so that calling it without a type argument explicitly returns any instead of inferring the type from the context. This prevents overloaded callees from incorrectly inferring the result type. A corresponding test case has been added to data-model.test.ts, and the CHANGELOG.md has been updated. There are no review comments, so I have no feedback to provide.
# Conflicts: # typescript/core/web_core/CHANGELOG.md
|
Hi @jacobsimionato, this adds the non-generic |
# Conflicts: # typescript/core/web_core/CHANGELOG.md
|
From triage bot, analysis: For humansTL;DR Summary: Targeted issues: Why flagged for triage: Suggestion:
To adjust the analysis and apply its suggestion, run in your a2ui checkout: tools/internal/triage/triage_ui.sh https://github.com/a2ui-project/a2ui/pull/4054For softwareThis analysis is auto-created to help humans to triage this item. Please, do not treat it as a team decision. 🤖 Agent-generated |
|
Thanks for the fix and the compile-time test. Assigning this PR to |
# Conflicts: # typescript/core/web_core/CHANGELOG.md
# Conflicts: # typescript/core/web_core/CHANGELOG.md
| @@ -1,5 +1,6 @@ | |||
| ## Unreleased | |||
|
|
|||
| - `DataModel.get(path)` called without a type argument returns `any` instead of inferring its result type from the context, so a call such as `expect(model.get(path))` no longer picks an overload of `expect` (for example an accessibility matcher's) from that inference. `get<T>(path)` still returns `T`. [#3784](https://github.com/a2ui-project/a2ui/issues/3784) | |||
There was a problem hiding this comment.
There's no blank line between this new entry and the ## 0.16.1 heading below it, which will cause the Presubmit Lint formatting check (prettier --check) to fail in CI. While adding that blank line, please also include a link to this PR (#4054) alongside the issue link per our changelog convention.
Additional details
Resolving the CHANGELOG.md merge conflict in 9c3cf2c9b3 dropped the blank line before ## 0.16.1. .github/workflows/presubmit-lint.yml runs ./scripts/fix_format.sh --check (prettier@3.8.4 --config .prettierrc --check .), which fails on this file as written. Also, per the changelog convention, entries should end with a link to their pull request ([#4054](https://github.com/a2ui-project/a2ui/pull/4054)).
| - `DataModel.get(path)` called without a type argument returns `any` instead of inferring its result type from the context, so a call such as `expect(model.get(path))` no longer picks an overload of `expect` (for example an accessibility matcher's) from that inference. `get<T>(path)` still returns `T`. [#3784](https://github.com/a2ui-project/a2ui/issues/3784) | |
| - `DataModel.get(path)` called without a type argument returns `any` instead of inferring its result type from the context, so a call such as `expect(model.get(path))` no longer picks an overload of `expect` (for example an accessibility matcher's) from that inference. `get<T>(path)` still returns `T`. [#3784](https://github.com/a2ui-project/a2ui/issues/3784), [#4054](https://github.com/a2ui-project/a2ui/pull/4054) | |
🤖 Agent-generated
# Conflicts: # typescript/core/web_core/CHANGELOG.md
…entry and keep the blank line before the heading
# Conflicts: # typescript/core/web_core/CHANGELOG.md
|
Hi @jacobsimionato, thanks for the approval. I've merged |
Description
DataModel.get<T = any>(path): Tlets TypeScript inferTfrom where the call sits. Inside an overloaded callee such asexpect(...)with an accessibility matcher augmentation (expect(actual: A11yCheckResult): A11yCheckJasmineMatcher),Tis inferred from that first overload's parameter, the overload matches, and the test fails to compile:This adds a non-generic
get(path: string): anyoverload ahead ofget<T>(path: string): T, as proposed in the issue. An untyped call now returnsany; overload resolution's first pass compares by subtype, andanyis not a subtype ofA11yCheckResult, so the genericexpect<T>overload is chosen.model.get<string>(path)still returnsstring. The implementation signature and body are unchanged.Verification:
data-model.test.tsdeclares a local overloadedcheck()and callscheck(model.get('/flag')).isFalse(). Its assertion is the build: with the change reverted,tscfails withTS2339: Property 'isFalse' does not exist on type '{ isOther(): boolean; }'.yarn testintypescript/core/web_core: 1535 passed, 0 failed.Fixes #3784
Pre-launch Checklist
One time:
For this PR: