diff --git a/goldens/public-api/core/index.api.md b/goldens/public-api/core/index.api.md index 7f0237fc9ae..48348e13ec4 100644 --- a/goldens/public-api/core/index.api.md +++ b/goldens/public-api/core/index.api.md @@ -1019,6 +1019,8 @@ export interface InputFunction { (initialValue: undefined, opts: InputOptionsWithoutTransform): InputSignal; (initialValue: T, opts: InputOptionsWithTransform): InputSignalWithTransform; (initialValue: undefined, opts: InputOptionsWithTransform): InputSignalWithTransform; + (initialValue: T, opts: InputOptionsWithTransform): InputSignalWithTransform; + (initialValue: undefined, opts: InputOptionsWithTransform): InputSignalWithTransform; required: { (opts?: InputOptionsWithoutTransform): InputSignal; (opts: InputOptionsWithTransform): InputSignalWithTransform; diff --git a/packages/core/src/authoring/input/input.ts b/packages/core/src/authoring/input/input.ts index a88007cd41b..dcc4394f8a8 100644 --- a/packages/core/src/authoring/input/input.ts +++ b/packages/core/src/authoring/input/input.ts @@ -77,6 +77,19 @@ export interface InputFunction { initialValue: undefined, opts: InputOptionsWithTransform, ): InputSignalWithTransform; + /** + * Declares an input of type `T` with an initial value and a transform function + * that accepts values of the same type. + */ + (initialValue: T, opts: InputOptionsWithTransform): InputSignalWithTransform; + /** + * Declares an input of type `T|undefined` without an initial value and with a transform + * function that accepts values of the same type. + */ + ( + initialValue: undefined, + opts: InputOptionsWithTransform, + ): InputSignalWithTransform; /** * Initializes a required input. diff --git a/packages/core/test/authoring/signal_input_signature_test.ts b/packages/core/test/authoring/signal_input_signature_test.ts index ba4a8c3c2e3..5f1d0a060ab 100644 --- a/packages/core/test/authoring/signal_input_signature_test.ts +++ b/packages/core/test/authoring/signal_input_signature_test.ts @@ -12,7 +12,7 @@ * the resulting types match our expectations (via comments asserting the `.d.ts`). */ -import {input} from '../../src/core'; +import {booleanAttribute, input, numberAttribute} from '../../src/core'; // import preserved to simplify `.d.ts` emit and simplify the `type_tester` logic. // tslint:disable-next-line no-duplicate-imports import {InputSignal, InputSignalWithTransform} from '../../src/core'; @@ -102,6 +102,19 @@ export class InputSignatureTest { transform: (v: string | boolean) => '', }); + /** boolean, boolean */ + explicitReadWithBooleanAttributeTransform = input(false, {transform: booleanAttribute}); + /** number, number */ + explicitReadWithNumberAttributeTransform = input(0, {transform: numberAttribute}); + /** boolean | undefined, boolean | undefined */ + explicitReadWithUndefinedInitialBooleanAttributeTransform = input(undefined, { + transform: booleanAttribute, + }); + /** number | undefined, number | undefined */ + explicitReadWithUndefinedInitialNumberAttributeTransform = input(undefined, { + transform: numberAttribute, + }); + /** string, string | boolean */ requiredWithTransformInferenceNoExplicitGeneric = input.required({ transform: (v: string | boolean) => '',