Type Utilities
TypeScript ships utility types like Omit
or Pick
that reshape types. When testing types of expressions, use the omit()
or pick()
utilities to have same results.
The utilities only reshape types. At runtime they return the same object that was passed as an argument.
omit()
The omit()
type utility reshapes type of the given object by removing the specified keys:
import { , , } from "tstyche";
class <> {
: <> = [];
get (): number {
return this..;
}
(: ): void {
this..();
}
}
((new (), "enqueue", "entries"))..<{
readonly : number;
}>();
// Equivalent to the 'Omit' utility type
<<<string>, "enqueue" | "entries">>()..<{
readonly : number;
}>();
pick()
The pick()
type utility reshapes type of the given object by keeping only the specified keys:
import { , , } from "tstyche";
class <> {
: <> = [];
get (): number {
return this..;
}
(: ): void {
this..();
}
}
((new (), "size"))..<{ readonly : number }>();
// Equivalent to the 'Pick' utility type
<<<string>, "size">>()..<{ readonly : number }>();
Last updated on