interface SomeObject {
id: string;
otherProp?: string;
}
const validate =
(value: unknown) => {
if (!value || typeof value !== "object" || !("id" in value) || typeof value.id !== "string") return;
return {
value: value satisfies SomeObject,
};
}
value does not satisfy SomeObject even that it is check if prop id exists and is string
https://tsplay.dev/WokBPW
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.