-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(core): add type tests for ɵunwrapWritableSignal (#54387)
Getting the typing for `ɵunwrapWritableSignal` just right was tricky so these changes add some tests to ensure that we don't regress. Also reworks the type tester a bit to make it easier to find where to add new test files. PR Close #54387
- Loading branch information
1 parent
0ecc2d1
commit 1581988
Showing
3 changed files
with
58 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/core/test/authoring/unwrap_writable_signal_signature_test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
/** | ||
* @fileoverview | ||
* This file contains various signal `model()` patterns and ensures | ||
* the resulting types match our expectations (via comments asserting the `.d.ts`). | ||
*/ | ||
|
||
import {input, model, signal, ɵunwrapWritableSignal as unwrapWritableSignal} from '@angular/core'; | ||
// clang-format off | ||
// import preserved to simplify `.d.ts` emit and simplify the `type_tester` logic. | ||
// tslint:disable-next-line no-duplicate-imports | ||
import {InputSignal, WritableSignal} from '@angular/core'; | ||
// clang-format on | ||
|
||
export class SignalModelSignatureTest { | ||
/** string | undefined */ | ||
optionalModel = unwrapWritableSignal(model<string>()); | ||
|
||
/** string */ | ||
requiredModel = unwrapWritableSignal(model.required<string>()); | ||
|
||
/** string | number */ | ||
writableSignal = unwrapWritableSignal(signal<string|number>(0)); | ||
|
||
/** InputSignal<string | undefined> */ | ||
optionalReadonlySignal = unwrapWritableSignal(input<string>()); | ||
|
||
/** InputSignal<string> */ | ||
requiredReadonlySignal = unwrapWritableSignal(input.required<string>()); | ||
|
||
/** number */ | ||
primitiveValue = unwrapWritableSignal(123); | ||
|
||
/** (value: string | null | undefined) => number */ | ||
getterFunction = | ||
unwrapWritableSignal((value: string|null|undefined) => value ? parseInt(value) : 0); | ||
} |