Bjorno
Bjorno
Aarktype
Created by Bjorno on 8/27/2024 in #questions
Extending types similar to an interface
How would one go about extending types similar to how one would extend an interface in TypeScript? It's really the only thing I feel like is missing for ArkType to be a viable alternative. A minimal example of what I want for ArkType, but written in TypeScript:
interface BaseTitle {
kind: 'series' | 'episode' | 'movie';
name: string;
seasonNumber?: string;
episodeNumber?: string;
seasonCount?: number;
episodeCount?: number;
}

interface SeriesTitle extends BaseTitle {
kind: 'series';
seasonCount: number;
episodeCount: number;
seasonNumber?: never;
episodeNumber?: never;
}

interface EpisodeTitle extends BaseTitle {
kind: 'episode';
seasonNumber: string;
episodeNumber: string;
seasonCount?: never;
episodeCount?: never;
}

interface MovieTitle extends BaseTitle {
kind: 'movie';
seasonNumber?: never;
episodeNumber?: never;
seasonCount?: never;
episodeCount?: never;
}

type Title = SeriesTitle | EpisodeTitle | MovieTitle;
interface BaseTitle {
kind: 'series' | 'episode' | 'movie';
name: string;
seasonNumber?: string;
episodeNumber?: string;
seasonCount?: number;
episodeCount?: number;
}

interface SeriesTitle extends BaseTitle {
kind: 'series';
seasonCount: number;
episodeCount: number;
seasonNumber?: never;
episodeNumber?: never;
}

interface EpisodeTitle extends BaseTitle {
kind: 'episode';
seasonNumber: string;
episodeNumber: string;
seasonCount?: never;
episodeCount?: never;
}

interface MovieTitle extends BaseTitle {
kind: 'movie';
seasonNumber?: never;
episodeNumber?: never;
seasonCount?: never;
episodeCount?: never;
}

type Title = SeriesTitle | EpisodeTitle | MovieTitle;
24 replies