Exposing a `make` method for an opaque type in TypeScript while maintaining type safety can indee...

when trying to expose struct as opaque type how do i also expose the make method?

const _OAuthSession = S.Struct({
  codeVerifier: S.String,
  createdAt: DateFromUnixTime,
  deviceId: S.optional(S.String),
})

export interface OAuthSession extends S.Schema.Type<typeof _OAuthSession> {}
export interface OAuthSessionEncoded extends S.Schema.Encoded<typeof _OAuthSession> {}

export const OAuthSession: S.Schema<OAuthSession, OAuthSessionEncoded> & {
  make: typeof _OAuthSession['make']
} = _OAuthSession


this feels hacky
Was this page helpful?