Skip to content

Commit 2ab638d

Browse files
committed
refactor(core): expose function to assert type of variables (angular#62648)
Adds the `ɵassertType` function that will be used during type checking to assert the type of a value. PR Close angular#62648
1 parent 53963e9 commit 2ab638d

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

packages/compiler/src/render3/r3_identifiers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,4 +469,5 @@ export class Identifiers {
469469
static InputSignalBrandWriteType = {name: 'ɵINPUT_SIGNAL_BRAND_WRITE_TYPE', moduleName: CORE};
470470
static UnwrapDirectiveSignalInputs = {name: 'ɵUnwrapDirectiveSignalInputs', moduleName: CORE};
471471
static unwrapWritableSignal = {name: 'ɵunwrapWritableSignal', moduleName: CORE};
472+
static assertType = {name: 'ɵassertType', moduleName: CORE};
472473
}

packages/core/src/core_private_export.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,4 @@ export {getClosestComponentName as ɵgetClosestComponentName} from './internal/g
171171
export {getComponentDef as ɵgetComponentDef} from './render3/def_getters';
172172
export {DEHYDRATED_BLOCK_REGISTRY as ɵDEHYDRATED_BLOCK_REGISTRY} from './defer/registry';
173173
export {TimerScheduler as ɵTimerScheduler} from './defer/timer_scheduler';
174+
export {ɵassertType} from './type_checking';

packages/core/src/type_checking.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*!
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
/**
10+
* Utility function used during template type checking to assert that a value is of a certain type.
11+
* @codeGenApi
12+
*/
13+
export function ɵassertType<T>(value: unknown): asserts value is T {}

packages/core/test/render3/jit_environment_spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const AOT_ONLY = new Set<string>([
3434
'ɵINPUT_SIGNAL_BRAND_WRITE_TYPE',
3535
'ɵUnwrapDirectiveSignalInputs',
3636
'ɵunwrapWritableSignal',
37+
'ɵassertType',
3738
]);
3839

3940
/**

0 commit comments

Comments
 (0)