Schemaから型を取り出す
このSchemaを例に取る
code:ts
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number
})
3種類の方法がある
code:ts
type Person1 = typeof Person.Type
type Person2 = Schema.Schema.Type<typeof Person>
interface Person3 extends Schema.Schema.Type<typeof Person> {}
1でええやんmrsekut.icon
何のために2番目あるんや
3番目は読みやすさとパフォーマンスが良いと書いているが、どこが読みやすいのかわからん
入力の型も得られる
.Encoded
code:ts
type Person_ = typeof Person.Encoded
Contextの型
code:ts
type PersonContext = typeof Person.Context
型の内部構造を隠蔽した型
code:ts
const _Person = Schema.Struct({
name: Schema.String,
age: Schema.Number
})
// Declare the type interface to make it opaque
interface Person extends Schema.Schema.Type<typeof _Person> {}
// Re-declare the schema as opaque
const Person: Schema.Schema<Person> = _Person