Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improve type inference for oEmbed type in TypeScript #113

Merged
merged 4 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 44 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,7 @@ type Metadata = {
author?: string
theme_color?: string
canonical_url?: string
oEmbed?: {
type: 'photo' | 'video' | 'link' | 'rich'
version?: string
title?: string
author_name?: string
author_url?: string
provider_name?: string
provider_url?: string
cache_age?: number
thumbnails?: [{
url?: string
width?: number
height?: number
}]
}
oEmbed?: OEmbedPhoto | OEmbedVideo | OEmbedLink | OEmbedRich
twitter_card: {
card: string
site?: string
Expand Down Expand Up @@ -147,6 +133,49 @@ type Metadata = {
}
}
}

type OEmbedBase = {
type: "photo" | "video" | "link" | "rich"
version: string
title?: string
author_name?: string
author_url?: string
provider_name?: string
provider_url?: string
cache_age?: number
thumbnails?: [
{
url?: string
width?: number
height?: number
}
]
}

type OEmbedPhoto = OEmbedBase & {
type: "photo"
url: string
width: number
height: number
}

type OEmbedVideo = OEmbedBase & {
type: "video"
html: string
width: number
height: number
}

type OEmbedLink = OEmbedBase & {
type: "link"
}

type OEmbedRich = OEmbedBase & {
type: "rich"
html: string
width: number
height: number
}
```

## The who 💖
Expand Down
63 changes: 44 additions & 19 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,7 @@
author?: string;
theme_color?: string;
canonical_url?: string;
oEmbed?: {
type: "photo" | "video" | "link" | "rich";
width?: number;
height?: number;
version?: string;
title?: string;
author_name?: string;
author_url?: string;
provider_name?: string;
provider_url?: string;
cache_age?: number;
thumbnails?: [
{
url?: string;
width?: number;
height?: number;
}
];
};
oEmbed?: OEmbedPhoto | OEmbedVideo | OEmbedLink | OEmbedRich;
twitter_card: {
card: string;
site?: string;
Expand Down Expand Up @@ -117,3 +99,46 @@
};
};
};

type OEmbedBase = {
type: "photo" | "video" | "link" | "rich";
version: string;
title?: string;
author_name?: string;
author_url?: string;
provider_name?: string;
provider_url?: string;
cache_age?: number;
thumbnails?: [
{
url?: string;
width?: number;
height?: number;
}
];
}

Check failure on line 119 in src/types.ts

View workflow job for this annotation

GitHub Actions / test (lts/-1)

Insert `;`

Check failure on line 119 in src/types.ts

View workflow job for this annotation

GitHub Actions / test (current)

Insert `;`

type OEmbedPhoto = OEmbedBase & {
type: "photo";
url: string;
width: number;
height: number;
}

Check failure on line 126 in src/types.ts

View workflow job for this annotation

GitHub Actions / test (lts/-1)

Insert `;`

Check failure on line 126 in src/types.ts

View workflow job for this annotation

GitHub Actions / test (current)

Insert `;`

type OEmbedVideo = OEmbedBase & {
type: "video";
html: string;
width: number;
height: number;
}

Check failure on line 133 in src/types.ts

View workflow job for this annotation

GitHub Actions / test (lts/-1)

Insert `;`

Check failure on line 133 in src/types.ts

View workflow job for this annotation

GitHub Actions / test (current)

Insert `;`

type OEmbedLink = OEmbedBase & {
type: "link";
}

Check failure on line 137 in src/types.ts

View workflow job for this annotation

GitHub Actions / test (lts/-1)

Insert `;`

Check failure on line 137 in src/types.ts

View workflow job for this annotation

GitHub Actions / test (current)

Insert `;`

type OEmbedRich = OEmbedBase & {
type: "rich";
html: string;
width: number;
height: number;
}

Check failure on line 144 in src/types.ts

View workflow job for this annotation

GitHub Actions / test (lts/-1)

Insert `;`

Check failure on line 144 in src/types.ts

View workflow job for this annotation

GitHub Actions / test (current)

Insert `;`
Loading