decodeUnknownPromise

Avatar of Hemanta SundarayHemanta Sundaray

decodeUnknownPromise returns a Promise instead of throwing or returning Exit / Option.

  • If decoding succeeds, the Promise resolves with the decoded value.
  • If decoding fails, the Promise rejects with a SchemaIssue.Issue.
schema.ts
import { Schema, SchemaIssue } from "effect";
const schema = Schema.Struct({
name: Schema.String,
age: Schema.Number,
});
const decode = Schema.decodeUnknownPromise(schema);
// Happy path
const decoded = await decode({ name: "Alice", age: 30 });
console.log("Decoded Value:", decoded);
// Error path
try {
await decode({ name: 42, age: "30" }, { errors: "all" });
} catch (issue) {
if (SchemaIssue.isIssue(issue)) {
console.log("Error Message:", String(issue));
console.log("Issue Tree:", issue);
}
}

Use decodeUnknownPromise when you want schema decoding to fit into async/await and Promise-based code.

Sign in to save progress

Stay in the loop

Get notified when new chapters are added and when this course is complete.