refactor(core): add utility type for extracting the value of a custom control

Adds the `ɵExtractFormControlValue` type that we can use during template type checking to extract the type of a custom control.

(cherry picked from commit 4b68bddd62)
This commit is contained in:
Kristiyan Kostadinov 2025-10-31 13:59:04 +01:00 committed by Andrew Scott
parent 96cb0cffda
commit 6df098f76c
5 changed files with 16 additions and 0 deletions

View file

@ -494,6 +494,7 @@ export class Identifiers {
// type-checking
static InputSignalBrandWriteType = {name: 'ɵINPUT_SIGNAL_BRAND_WRITE_TYPE', moduleName: CORE};
static UnwrapDirectiveSignalInputs = {name: 'ɵUnwrapDirectiveSignalInputs', moduleName: CORE};
static ExtractFormControlValue = {name: 'ɵExtractFormControlValue', moduleName: CORE};
static unwrapWritableSignal = {name: 'ɵunwrapWritableSignal', moduleName: CORE};
static assertType = {name: 'ɵassertType', moduleName: CORE};
}

View file

@ -95,6 +95,7 @@ export {
ɵɵcontentQuerySignal,
ɵɵcontrol,
ɵɵcontrolCreate,
ɵExtractFormControlValue,
ɵɵcomponentInstance,
ɵɵCopyDefinitionFeature,
ɵɵdefineComponent,

View file

@ -97,6 +97,7 @@ export {
ɵɵproperty,
ɵɵcontrol,
ɵɵcontrolCreate,
ɵExtractFormControlValue,
ɵɵcontentQuery,
ɵɵcontentQuerySignal,
ɵɵloadQuery,

View file

@ -32,6 +32,18 @@ import {listenToOutput} from '../view/directive_outputs';
import {listenToDomEvent, wrapListener} from '../view/listeners';
import {setPropertyAndInputs, storePropertyBindingMetadata} from './shared';
import {writeToDirectiveInput} from './write_to_directive_input';
import {ModelSignal} from '../../authoring/model/model_signal';
/**
* Used during template type checking to extract the type of a custom form control.
*
* @codeGenApi
*/
export type ɵExtractFormControlValue<T> = T extends {value: ModelSignal<infer V>}
? V
: T extends {checked: ModelSignal<boolean>}
? boolean
: unknown;
/**
* Possibly sets up a {@link ɵControl} to manage a native or custom form control.

View file

@ -38,6 +38,7 @@ const AOT_ONLY = new Set<string>([
// used in type-checking.
'ɵINPUT_SIGNAL_BRAND_WRITE_TYPE',
'ɵExtractFormControlValue',
'ɵUnwrapDirectiveSignalInputs',
'ɵunwrapWritableSignal',
'ɵassertType',