Rebasely Beta: data may be purged

justintypescript-ultra-strict Public

Text · 38 lines · 1.1 KiB · at 74947de

import { Ok, Err, Some, type Result, type Option } from "@tsus/runtime";const parse = (raw: string): Result<number, string> => (raw === "" ? Err("empty") : Ok(raw.length));// TSUS300: the function does not declare a Result or Option return type.const total = (raw: string): number => {  const n = parse(raw)?;  return n;};// TSUS300: no function to return from at all.const top = parse("abc")?;// TSUS301: ? needs a Result or Option, not a string.const name = (raw: string): Result<string, string> => {  const s = raw?;  return Ok(s);};// TSUS302: the Err carries a string but the function's error type is number.const coded = (raw: string): Result<number, number> => {  const n = parse(raw)?;  return Ok(n);};// TSUS302: None cannot propagate out of a function returning Result.const fromOption = (o: Option<number>): Result<number, string> => {  const n = o?;  return Ok(n);};// TSUS303: the right side of && may not run, so it cannot hold a ?.const guarded = (raw: string): Result<boolean, string> => {  const ok = raw.length > 0 && (parse(raw)?) > 1;  return Ok(ok);};console.log(total, top, name, coded, fromOption, guarded, Some);