File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -120,6 +120,31 @@ const BUILTIN_CALENDAR_IDS = [
120
120
'gregory'
121
121
] ;
122
122
123
+ /*
124
+ * uncheckedAssertNarrowedType forces TypeScript to change the type of the argment to the one given in
125
+ * the type parameter. This should only be used to help TS understand when variables change types,
126
+ * but TS can't or won't infer this automatically. They should be used sparingly, because
127
+ * if used incorrectly can lead to difficult-to-diagnose problems.
128
+ */
129
+ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
130
+ export function uncheckedAssertNarrowedType < T = unknown > (
131
+ arg : unknown ,
132
+ justification : string
133
+ ) : asserts arg is T extends typeof arg ? T : never { }
134
+ /* eslint-enable */
135
+ /**
136
+ * In debug builds, this function verifies that the given argument "exists" (is not
137
+ * null or undefined). This function becomes a no-op in the final bundles distributed via NPM.
138
+ * @param arg
139
+ */
140
+ function assertExists < A > ( arg : A ) : asserts arg is NonNullable < A > {
141
+ if ( DEBUG ) {
142
+ if ( arg != null ) {
143
+ throw new Error ( 'Expected arg to be set.' ) ;
144
+ }
145
+ }
146
+ }
147
+
123
148
function IsInteger ( value : unknown ) : value is number {
124
149
if ( typeof value !== 'number' || ! NumberIsFinite ( value ) ) return false ;
125
150
const abs = MathAbs ( value ) ;
You can’t perform that action at this time.
0 commit comments