MCPcopy Index your code
hub / github.com/Effect-TS/effect / intersectTypeLiterals

Function intersectTypeLiterals

packages/effect/src/Schema.ts:3271–3299  ·  view source on GitHub ↗
(
  x: AST.AST,
  y: AST.AST,
  path: ReadonlyArray<PropertyKey>
)

Source from the content-addressed store, hash-verified

3269export const mutable = <S extends Schema.Any>(schema: S): mutable<S> => make(AST.mutable(schema.ast))
3270
3271const intersectTypeLiterals = (
3272 x: AST.AST,
3273 y: AST.AST,
3274 path: ReadonlyArray<PropertyKey>
3275): AST.TypeLiteral => {
3276 if (AST.isTypeLiteral(x) && AST.isTypeLiteral(y)) {
3277 const propertySignatures = [...x.propertySignatures]
3278 for (const ps of y.propertySignatures) {
3279 const name = ps.name
3280 const i = propertySignatures.findIndex((ps) => ps.name === name)
3281 if (i === -1) {
3282 propertySignatures.push(ps)
3283 } else {
3284 const { isOptional, type } = propertySignatures[i]
3285 propertySignatures[i] = new AST.PropertySignature(
3286 name,
3287 extendAST(type, ps.type, path.concat(name)),
3288 isOptional,
3289 true
3290 )
3291 }
3292 }
3293 return new AST.TypeLiteral(
3294 propertySignatures,
3295 x.indexSignatures.concat(y.indexSignatures)
3296 )
3297 }
3298 throw new Error(errors_.getSchemaExtendErrorMessage(x, y, path))
3299}
3300
3301const preserveRefinementAnnotations = AST.omitAnnotations([AST.IdentifierAnnotationId])
3302

Callers 1

intersectUnionMembersFunction · 0.85

Calls 1

extendASTFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…