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

fix: fixed missing types for ArraySupport plugin #1401

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, stri
declare function dayjs (date?: dayjs.ConfigType, format?: dayjs.OptionType, locale?: string, strict?: boolean): dayjs.Dayjs

declare namespace dayjs {
export type ConfigType = string | number | Date | Dayjs
interface ConfigTypeMap {
default: string | number | Date | Dayjs
}

export type ConfigType = ConfigTypeMap[keyof ConfigTypeMap]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this used for please? And will this affect the original type if the plugin is imported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamkun The type keyword doesn't support declaration merging. And yes, it will add the plugin's type into ConfigType.

ConfigTypeMap[keyof ConfigTypeMap] basically means "merge every members' type into a union". If no plugin was imported, the type of ConfigType is string | number | Date | Dayjs (same as before). When the ArraySupport plugin was imported, ConfigType will become string | number | Date | Dayjs | [year?: number, ...].

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks cool, does this requires higher ts version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamkun Labeled tuple elements require TypeScript 4.0 or higher, I can convert it back to un-labelled ones if you want to support older TypeScript versions.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's what I'm concerned. We should have a fallback support at least ts 3 I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamkun It should work on TypeScript 3 now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make sure that ConfigTypeMap[keyof ConfigTypeMap] works on ts3?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make sure that ConfigTypeMap[keyof ConfigTypeMap] works on ts3?

@iamkun Yes, this will work on TypeScript 3. You can verify it on TypeScript playground.


export type OptionType = { locale?: string, format?: string, utc?: boolean } | string | string[]

Expand Down
6 changes: 6 additions & 0 deletions types/plugin/arraySupport.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { PluginFunc } from 'dayjs'

declare module 'dayjs' {
interface ConfigTypeMap {
arraySupport: [number?, number?, number?, number?, number?, number?, number?]
}
}

declare const plugin: PluginFunc
export = plugin