Skip to content

Commit

Permalink
feat(fff): ✨ provide generics for types
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Jun 28, 2023
1 parent 2e15730 commit 2cc0b29
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/version/1.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ title: 'Version 1.1'

- Improve:
- [DateTime](#datetime) no longer supports number
- Provide generics for types

## Base

Expand Down
37 changes: 30 additions & 7 deletions packages/fff-flavored-frontmatter/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
/// <reference lib="dom" />

/**
* Optional Type Util
* @public
* @typeParam T - whether to support optional types
* - undefined: all available
* - true: only optional types are supported
* - false: optional types are not supported
*/
export type FFFOptionalType<T extends (boolean | undefined), Required, Optional> =
T extends undefined
? Required | Optional
: T extends true
? Optional
: Required

/**
* Object Image
* @public
Expand Down Expand Up @@ -75,16 +90,20 @@ export type FFFDateTime = {
/**
* Media Variables
* @public
* @typeParam T - whether to support optional types
* - undefined: all available
* - true: only optional types are supported
* - false: optional types are not supported
*/
export type FFFMedia = {
export type FFFMedia<T extends (boolean | undefined) = undefined> = {
/** the main image for article or photo post. */
image?: string | FFFImage
image?: FFFOptionalType<T, string, FFFImage>
/** the image for multi-photo post. */
images?: string[] | FFFImage[]
images?: FFFOptionalType<T, string[], FFFImage[]>
/** the main audio for audio post. */
audio?: string | FFFAudio
audio?: FFFOptionalType<T, string, FFFAudio>
/** the main video for video post. */
video?: string | FFFVideo
video?: FFFOptionalType<T, string, FFFVideo>
/** image alternate text. */
alt?: string
}
Expand Down Expand Up @@ -126,9 +145,13 @@ export type FFFExtra = {
/**
* Type definition of the {@link https://fff.js.org | FFF Flavored Frontmatter}.
* @public
* @typeParam T - whether to support optional types
* - undefined: all available
* - true: only optional types are supported
* - false: optional types are not supported
*/
export type FFFFlavoredFrontmatter = FFFBase &
export type FFFFlavoredFrontmatter<T extends (boolean | undefined) = undefined> = FFFBase &
FFFDateTime &
FFFMedia &
FFFMedia<T> &
FFFMention &
FFFExtra

0 comments on commit 2cc0b29

Please sign in to comment.