image2text

Untitled

Aug 4th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. LX) ‘
  2. declare function assert(value: unknown): asserts value;
  3. declare function assertIsArrayOfStrings(obj: unknown): asserts obj is string[];
  4. declare function assertNonNull<T>(obj: T): asserts obj is NonNullable<T>;
  5. function f1(x: unknown) {
  6. assert(typeof x === "string");
  7. return x.length; // x has type string here
  8. !
  9. function f2(x: unknown) {
  10. assertIsArray0fStrings(x);
  11. return x[0].length; // x has type string[] here
  12. }
  13. function f3(x: string | undefined) {
  14. assertNonNull(x);
  15. return x.length; // x has type string here
  16. h
Advertisement
Add Comment
Please, Sign In to add comment