Skip to content

Commit c023e8d

Browse files
devversionthePunderWoman
authored andcommitted
refactor(core): improve IDE completion of read option for signal queries (angular#54280)
This commit improves IDE completion of the `read` option for signal-based queries. Currently, TS only matches the first overload when starting out with defining a query. TS doesn't build up the combination of possible options from the second overload- so in practice users will only see IDE completions for the `descendants` option. This is not a problem for view queries as the only option is `read`, so TS will always match the overload with the `read` option. ``` class X { query = contentChild('', {^^ <-- here we should completion for `read` an `descendants` } ``` PR Close angular#54280
1 parent 1fb0da2 commit c023e8d

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

goldens/public-api/core/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ export interface ContentChildDecorator {
344344
export interface ContentChildFunction {
345345
<LocatorT>(locator: ProviderToken<LocatorT> | string, opts?: {
346346
descendants?: boolean;
347+
read?: undefined;
347348
}): Signal<LocatorT | undefined>;
348349
// (undocumented)
349350
<LocatorT, ReadT>(locator: ProviderToken<LocatorT> | string, opts: {
@@ -353,6 +354,7 @@ export interface ContentChildFunction {
353354
required: {
354355
<LocatorT>(locator: ProviderToken<LocatorT> | string, opts?: {
355356
descendants?: boolean;
357+
read?: undefined;
356358
}): Signal<LocatorT>;
357359
<LocatorT, ReadT>(locator: ProviderToken<LocatorT> | string, opts: {
358360
descendants?: boolean;
@@ -370,6 +372,7 @@ export const ContentChildren: ContentChildrenDecorator;
370372
// @public (undocumented)
371373
export function contentChildren<LocatorT>(locator: ProviderToken<LocatorT> | string, opts?: {
372374
descendants?: boolean;
375+
read?: undefined;
373376
}): Signal<ReadonlyArray<LocatorT>>;
374377

375378
// @public (undocumented)

packages/core/src/authoring/queries.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,11 @@ export interface ContentChildFunction {
138138
* Consider using `contentChild.required` for queries that should always match.
139139
* @developerPreview
140140
*/
141-
<LocatorT>(locator: ProviderToken<LocatorT>|string, opts?: {descendants?: boolean}):
142-
Signal<LocatorT|undefined>;
141+
<LocatorT>(locator: ProviderToken<LocatorT>|string, opts?: {
142+
descendants?: boolean,
143+
read?: undefined
144+
}): Signal<LocatorT|undefined>;
145+
143146
<LocatorT, ReadT>(locator: ProviderToken<LocatorT>|string, opts: {
144147
descendants?: boolean, read: ProviderToken<ReadT>
145148
}): Signal<ReadT|undefined>;
@@ -150,8 +153,11 @@ export interface ContentChildFunction {
150153
* @developerPreview
151154
*/
152155
required: {
153-
<LocatorT>(locator: ProviderToken<LocatorT>|string, opts?: {descendants?: boolean}):
154-
Signal<LocatorT>;
156+
<LocatorT>(locator: ProviderToken<LocatorT>|string, opts?: {
157+
descendants?: boolean,
158+
read?: undefined,
159+
}): Signal<LocatorT>;
160+
155161
<LocatorT, ReadT>(
156162
locator: ProviderToken<LocatorT>|string,
157163
opts: {descendants?: boolean, read: ProviderToken<ReadT>}): Signal<ReadT>;
@@ -187,7 +193,7 @@ export const contentChild: ContentChildFunction = (() => {
187193

188194
export function contentChildren<LocatorT>(
189195
locator: ProviderToken<LocatorT>|string,
190-
opts?: {descendants?: boolean}): Signal<ReadonlyArray<LocatorT>>;
196+
opts?: {descendants?: boolean, read?: undefined}): Signal<ReadonlyArray<LocatorT>>;
191197
export function contentChildren<LocatorT, ReadT>(
192198
locator: ProviderToken<LocatorT>|string,
193199
opts: {descendants?: boolean, read: ProviderToken<ReadT>}): Signal<ReadonlyArray<ReadT>>;

0 commit comments

Comments
 (0)