import { expect, it } from "vitest";
import { Equal, Expect } from "../helpers/type-utils";
export const values = ["a", "b", undefined, "c", undefined];
const filteredValues = values.filter((value): value is string => Boolean(value));
it("Should filter out the undefined values", () => {
expect(filteredValues).toEqual(["a", "b", "c"]);
});
it('Should be of type "string[]"', () => {
type test1 = Expect<Equal<typeof filteredValues, string[]>>;
});
https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates
标签:Typescript,undefined,value,Should,values,predicates,Using,type From: https://www.cnblogs.com/Answer1215/p/17107629.html