Issue
This code fails to compile:
const nodeIsUseless = (node: unknown) =>
node !== null &&
typeof node === "object" &&
"type" in node &&
typeof node.type === "string" &&
node.type === "JSXText";
because on the last 2 lines:
Property 'type' does not exist on type 'object'.(2339)
...which I can understand by itself, but I do not understand why after "type" in node check, TS infers node to still be of type object instead of type { type: unknown; [key: string]: unknown }, which would not trigger error.
Solution
While the code is correct, TypeScript doesn't have the capability to infer { type: unknown } from "type" in node but this feature is currently in development
Answered By - Nino Filiu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.