-
-
Notifications
You must be signed in to change notification settings - Fork 5
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/[email protected]/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/[email protected]/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/[email protected]/mod.ts";
const x: unknown = ["a", "b", "c"];
if (isArray(x, isString)) {
// ...
}
import { is } from "https://deno.land/x/[email protected]/mod.ts";
const x: unknown = ["a", "b", "c"];
if (is.ArrayOf(is.String)(x)) {
// ...
}
import { isObject } from "https://deno.land/x/[email protected]/mod.ts";
const x: unknown = { a: "a", b: "b", c: "c" };
if (isObject(x)) {
// ...
}
import { is } from "https://deno.land/x/[email protected]/mod.ts";
const x: unknown = { a: "a", b: "b", c: "c" };
if (is.Record(x)) {
// ...
}
import {
isObject,
isString,
} from "https://deno.land/x/[email protected]/mod.ts";
const x: unknown = { a: "a", b: "b", c: "c" };
if (isObject(x, isString)) {
// ...
}
import { is } from "https://deno.land/x/[email protected]/mod.ts";
const x: unknown = { a: "a", b: "b", c: "c" };
if (is.RecordOf(is.String)(x)) {
// ...
}
import { isLike } from "https://deno.land/x/[email protected]/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/[email protected]/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)) {
// ...
}