You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ChadScript's type system supports union types (per chadscript.d.ts: "Union Types — string | number support"), but string | null (nullable string) is not formalized as a first-class pattern with proper narrowing. This bites FFI and any code that needs "maybe-a-value" semantics.
Why it matters
Every library that calls C code hits this. C convention: return NULL to mean "no value" / "error". Currently chad's only options are:
Chad has union types, narrowing patterns for other unions, and NaN/tagged sentinel infrastructure for JS-compatible null/undefined. The pieces exist. The question is whether string | null specifically round-trips cleanly through the type system and codegen.
Impact
Unblocks:
Cleaner FFI surface for every C library wrapper
Optional return values from user code (function lookup(key: string): Record | null)
Eliminates the isOpen() / hasValue() probe pattern from lib/net.ts, future Postgres driver, etc.
Better TypeScript compatibility (nullable types are ubiquitous in real TS code)
Summary
ChadScript's type system supports union types (per
chadscript.d.ts: "Union Types — string | number support"), butstring | null(nullable string) is not formalized as a first-class pattern with proper narrowing. This bites FFI and any code that needs "maybe-a-value" semantics.Why it matters
Every library that calls C code hits this. C convention: return
NULLto mean "no value" / "error". Currently chad's only options are:""(lossy — can't distinguish "unset" from "empty string"; see ffi: NULL char* does not reliably round-trip to empty string in TS #591)isOpen(),hasValue()) on every wrapperNeither is ergonomic for user code.
string | nullwith TypeScript-style narrowing (if (x !== null) { x.foo() }) is the right shape.What "support" means concretely
string | nullas a valid type annotation that typechecks and compilesconst x: string | null = null;if (x !== null),xhas typestringand methods worki8*declared asstring | nullmap NULL →null, non-null → stringconst empty: string = ""; const missing: string | null = null; empty === missing→ falseWhy it's probably already near-implemented
Chad has union types, narrowing patterns for other unions, and NaN/tagged sentinel infrastructure for JS-compatible null/undefined. The pieces exist. The question is whether
string | nullspecifically round-trips cleanly through the type system and codegen.Impact
Unblocks:
function lookup(key: string): Record | null)isOpen()/hasValue()probe pattern fromlib/net.ts, future Postgres driver, etc.Related
char*FFI (the current workaround is coerce-to-empty-string; fixingstring | nullmakes that workaround unnecessary)