- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 6
Migration (v2 to v3)
        Λlisue (Ali sue・ありすえ) edited this page Aug 2, 2024 
        ·
        3 revisions
      
    - https://github.com/vim-denops/denops.vim/pull/261/commits/16455a3342d7739bc282f52337bbec6981d0331a
- https://github.com/vim-denops/deno-denops-std/pull/215/commits/ef32620ed276b5e4de977b20505245a546cf6061
- https://github.com/lambdalisue/gin.vim/pull/87/commits/d8ae09da315fd0577ccc35cff518ec98a01aaee2
Use assert, ensure, or maybe function with corresponding is* predicate functions instead of assert*, ensure*, or maybe*
import {
  assertString,
  ensureString,
  maybeString,
} from "https://deno.land/x/unknownutil@v2.1.1/mod.ts";
const x: unknown = "Hello";
assertString(x);
const _ = ensureString(x);
const __ = maybeString(x) ?? "default";import {
  assert,
  ensure,
  is,
  maybe,
} from "https://deno.land/x/unknownutil@v3.0.1/mod.ts";
const x: unknown = "Hello";
assert(x, is.String);
const _ = ensure(x, is.String);
const __ = maybe(x, is.String) ?? "default";import {
  isArray,
  isString,
} from "https://deno.land/x/unknownutil@v2.1.1/mod.ts";
const x: unknown = ["a", "b", "c"];
if (isArray(x, isString)) {
  // ...
}import { is } from "https://deno.land/x/unknownutil@v3.0.1/mod.ts";
const x: unknown = ["a", "b", "c"];
if (is.ArrayOf(is.String)(x)) {
  // ...
}import { isObject } from "https://deno.land/x/unknownutil@v2.1.1/mod.ts";
const x: unknown = { a: "a", b: "b", c: "c" };
if (isObject(x)) {
  // ...
}import { is } from "https://deno.land/x/unknownutil@v3.0.1/mod.ts";
const x: unknown = { a: "a", b: "b", c: "c" };
if (is.Record(x)) {
  // ...
}import {
  isObject,
  isString,
} from "https://deno.land/x/unknownutil@v2.1.1/mod.ts";
const x: unknown = { a: "a", b: "b", c: "c" };
if (isObject(x, isString)) {
  // ...
}import { is } from "https://deno.land/x/unknownutil@v3.0.1/mod.ts";
const x: unknown = { a: "a", b: "b", c: "c" };
if (is.RecordOf(is.String)(x)) {
  // ...
}import { isLike } from "https://deno.land/x/unknownutil@v2.1.1/mod.ts";
const a: unknown = ["a", 0, "b"];
if (isLike(["", 0, ""], a)) {
  // ...
}
const c: unknown = { foo: "foo", bar: 100 };
if (isLike({ foo: "", bar: 0 }, a)) {
  // ...
}import { is } from "https://deno.land/x/unknownutil@v3.0.1/mod.ts";
const a: unknown = ["a", 0, "b"];
// NOTE that `isTupleOf` require `readonly` array (`as const`)
if (is.TupleOf([is.String, is.Number, is.String] as const)(x)) {
  // ...
}
const c: unknown = { foo: "foo", bar: 100 };
if (is.ObjectOf({ foo: is.String, bar: is.Number })(a)) {
  // ...
}