From 4b299fee3a8d809c984a83cb43b897db4da54b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Moreau?= Date: Mon, 30 Sep 2024 13:13:02 +0200 Subject: [PATCH] Update README.md --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f8abe91..a56bea5 100644 --- a/README.md +++ b/README.md @@ -85,11 +85,15 @@ If the condition requires a parameter, `assert` and `check` will require it. Finally, if the condition is a type guard, the parameter you pass will be inferred automatically. -Note: for convenience, the condition can be a boolean value but you will lose type inference. - ## Defining Policies To define policies, you create a policy set using the `definePolicies` function. Each policy definition is created using the `definePolicy` function, which takes a policy name and a callback that defines the policy logic (or a boolean value). + +> [!IMPORTANT] +> For convenience, the condition can be a boolean value but **you will lose type inference** +> +> If you want TS to infer something (not null, union, etc), use a condition function + The callback logic can receive a unique parameter (scalar or object) and return a boolean value or a a type predicate. You can also provide an error factory to the policy (3rd argument) to customize the error message. @@ -141,7 +145,7 @@ const OrgPolicies = definePolicies((context: MyContext) => (orgId: string) => { () => currentUserOrgRole === "superadmin", () => check(adminGuard.policy("has app admin role")) ), - definePolicy("is superadmin", currentUserOrgRole === "superadmin"), // lazy evaluation + definePolicy("is superadmin", () => currentUserOrgRole === "superadmin"), ]; });