Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LX) ‘
- declare function assert(value: unknown): asserts value;
- declare function assertIsArrayOfStrings(obj: unknown): asserts obj is string[];
- declare function assertNonNull<T>(obj: T): asserts obj is NonNullable<T>;
- function f1(x: unknown) {
- assert(typeof x === "string");
- return x.length; // x has type string here
- !
- function f2(x: unknown) {
- assertIsArray0fStrings(x);
- return x[0].length; // x has type string[] here
- }
- function f3(x: string | undefined) {
- assertNonNull(x);
- return x.length; // x has type string here
- h
Advertisement
Add Comment
Please, Sign In to add comment