Upgrading from 0.25.24 t0 0.27.8 - issues with Type.Intersect #393
-
We recently found the need to update to 0.26+ due to needing
An example of what we were previously using in 0.25.24:
Kind of at a loss where to go from here. I also saw in the examples section an |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@tgilino Hi, Yeah, there has been quite a few changes from 0.26.0 with respect to intersection types. The composite type is provided as a fallback, however to keep composite inline with the new type model, this type also performs an IntersectLegacy TypeYou can just import the intersect example from here and replace import { IntersectLegacy } from './intersect-legacy' // you will need to copy and paste file into your project
// ...
Type.Pick(
IntersectLegacy([ // Just replace instances of Type.Intersect with IntersectLegacy
TypeWithALotOfProperties,
Type.Object({
C: Type.Optional(CTypeEnumSchema),
}),
]),
[A List of Properties ],
), TypeBuilder with IntersectLegacy TypeIf you want to include the legacy intersect type on the type builder, you will need to extend and re export the import { ExtendedTypeBuilder, ObjectOptions, TObject } from '@sinclair/typebox'
import { IntersectLegacy, TIntersectLegacy } from './legacy/intersect'
export class ApplicationTypeBuilder extends ExtendedTypeBuilder {
public IntersectLegacy<T extends TObject[]>(objects: [...T], options: ObjectOptions = {}): TIntersectLegacy<T> {
return IntersectLegacy<T>(objects, options)
}
}
// re-export the new type builder
export const Type = new ApplicationTypeBuilder() Then import the extended application type builder and use as normal. import { Type } from './application-types'
// ...
Type.Pick(
Type.IntersectLegacy([ // Now available on TypeBuilder
TypeWithALotOfProperties,
Type.Object({
C: Type.Optional(CTypeEnumSchema),
}),
]),
[A List of Properties ],
), Hope this helps |
Beta Was this translation helpful? Give feedback.
@tgilino Hi,
Yeah, there has been quite a few changes from 0.26.0 with respect to intersection types. The composite type is provided as a fallback, however to keep composite inline with the new type model, this type also performs an
X extends Y
per property check to determine if overlapping properties would yieldTNever
. This check is only supported for known types (not unsafe types, hence theExtends
error you see). I may investigate ways to relax this check in future revisions.IntersectLegacy Type
You can just import the intersect example from here and replace
Type.Intersect
forIntersectLegacy