Skip to content

Commit

Permalink
fix typings
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberCookie committed Oct 13, 2024
1 parent f91c5a5 commit 0ebb5e4
Show file tree
Hide file tree
Showing 16 changed files with 458 additions and 76 deletions.
2 changes: 1 addition & 1 deletion bin/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Command<R extends Obj | undefined> = {
description: string
commandAction(params: ActionParam<R>): void
example?: boolean | string | CommandExampleFn
} & (R extends undefined ? {} : CommandWithParams<R>)
} & (R extends undefined ? object : CommandWithParams<R>)

type FullCommand = Command<Obj>

Expand Down
2 changes: 1 addition & 1 deletion client_core/router/Link/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Props = PropsComponentBase<
} & LinkReactTagAttributes
>

type DefaultProps = {}
type DefaultProps = object

type MergedProps = Props & DefaultProps

Expand Down
18 changes: 9 additions & 9 deletions client_core/router/Router/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Transition = {
}

type LazyComponentIdentifier = {
_init?: Function
_init?: AnyFunc
}

type PageProps = {
Expand All @@ -82,7 +82,7 @@ type RedirectToPathObj = {



type RouteConfigAllFields<_WithPageExtend = {}> = {
type RouteConfigAllFields<_WithPageExtend = object> = {
/** Page to render */
Page: Page | LazyPage

Expand Down Expand Up @@ -127,20 +127,20 @@ type PageLayoutCommons = {
}


type RoutePageConfig<_WithPageExtend = {}> = {
type RoutePageConfig<_WithPageExtend = object> = {
Page: RouteConfigAllFields['Page']
paramName?: RouteConfigAllFields['paramName']
} & _WithPageExtend
type NeverPageConfig = Never<RoutePageConfig>


type RouteLayoutConfig<_WithPageExtend = {}> = {
type RouteLayoutConfig<_WithPageExtend = object> = {
Layout: RouteConfigAllFields['Layout']
} & _WithPageExtend
type NeverLayoutConfig = Never<RouteLayoutConfig>


type RouteChildrenConfig<_WithPageExtend = {}> = {
type RouteChildrenConfig<_WithPageExtend = object> = {
children: RouteConfigAllFields<_WithPageExtend>['children']
transition?: RouteConfigAllFields['transition']
}
Expand All @@ -161,15 +161,15 @@ type NeverPermissionsConfig = Never<RoutePermissionsConfig>



type RouteWithPageLayoutCommon<_WithPageExtend = {}> = PageLayoutCommons
type RouteWithPageLayoutCommon<_WithPageExtend = object> = PageLayoutCommons
& (RouteChildrenConfig<_WithPageExtend> | NeverChildrenConfig)
& (RoutePermissionsConfig | NeverPermissionsConfig)

type RouteWithPageConfig<_WithPageExtend = {}> = RouteWithPageLayoutCommon<_WithPageExtend>
type RouteWithPageConfig<_WithPageExtend = object> = RouteWithPageLayoutCommon<_WithPageExtend>
& RoutePageConfig<_WithPageExtend>
& NeverLayoutConfig

type RouteWithLayoutConfig<_WithPageExtend = {}> = RouteWithPageLayoutCommon<_WithPageExtend>
type RouteWithLayoutConfig<_WithPageExtend = object> = RouteWithPageLayoutCommon<_WithPageExtend>
& RouteLayoutConfig<_WithPageExtend>
& NeverPageConfig

Expand All @@ -186,7 +186,7 @@ type RouteWithRedirectConfig = RouteRedirectConfig



type RoutesConfig<_WithPageExtend = {}> = Obj<
type RoutesConfig<_WithPageExtend = object> = Obj<
RouteWithPageConfig<_WithPageExtend>
| RouteWithLayoutConfig<_WithPageExtend>
| RouteWithChildrenConfig
Expand Down
4 changes: 2 additions & 2 deletions client_core/store/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ type InnerStore<State extends Obj, A extends ActionsUnbinded<State>> = {
actions?: ActionsBinded<A>
}

type StoreShouldUpdate<State extends StateWithUpdater<{}>> = (
type StoreShouldUpdate<State extends StateWithUpdater<object>> = (
prevState: State,
newState: State
) => boolean

type StoreListenerWithPrevState<State = StateWithUpdater<{}>> = {
type StoreListenerWithPrevState<State = StateWithUpdater<object>> = {
(newState: State, prevState: State): void
withShouldUpdateCb: boolean
}
Expand Down
2 changes: 1 addition & 1 deletion client_core/ui/Link/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Props = PropsComponentBase<{

type Component = CoreUIComponent<Props, DefaultProps>

type DefaultProps = {}
type DefaultProps = object


export type { Props, DefaultProps, Component }
3 changes: 0 additions & 3 deletions client_core/ui/Ranger/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ type Props = PropsComponentThemed<Theme, {
* @param value new range value
* @param event mousedown event
*/


/* eslint-disable-next-line */
onChange?(value: Props['value'], event: MouseEvent | React.MouseEvent<HTMLDivElement>): void

/**
Expand Down
2 changes: 1 addition & 1 deletion client_core/ui/Table/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ type Props = PropsComponentBase<{
rootTagAttributes?: CoreUIReactTagAttributes<HTMLTableElement, React.TableHTMLAttributes<HTMLTableElement>>
}>

type DefaultProps = {}
type DefaultProps = object

type Component = CoreUIComponent<Props, DefaultProps>

Expand Down
2 changes: 1 addition & 1 deletion common/deep/clone/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type Options = {
funcClone?(value: Function): Function
funcClone?(value: AnyFunc): AnyFunc
}


Expand Down
4 changes: 2 additions & 2 deletions core/client_build/module_rules/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type MergeLoadersFn = (



type WebpackLoaderObj = Exclude<NonNullable<RuleSetUseItem>, string | Function>
type WebpackLoaderObj = Exclude<NonNullable<RuleSetUseItem>, string | AnyFunc>
type WebpackLoaderObjOptions = WebpackLoaderObj['options']


Expand Down Expand Up @@ -83,7 +83,7 @@ type Loaders<
_DefaultRuleLoaders = Exclude<_DefaultRule, null>['loaders']
> = (
_DefaultRule extends null
? {}
? object
: { [ K in keyof _DefaultRuleLoaders]?: Loader<NonNullable<_DefaultRuleLoaders[K]>> }
) & Obj<Loader>

Expand Down
22 changes: 13 additions & 9 deletions core/client_build/plugins/merge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { WebpackPluginInstance } from 'webpack'
import type {
DefaultPlugins, Plugins, AllCaseUserPluginConfig, PluginConfigInstance,
UserPluginObjectConfig, DefaultPluginsKeys
UserPluginObjectConfig, DefaultPluginsKeys, DefaultPluginsIntersact
} from './types'


Expand All @@ -19,18 +19,22 @@ const mergeOptions = (
: userOptions
)

function addWithoutMerge(result: WebpackPluginInstance[], pluginConfig: UserPluginObjectConfig) {
function addWithoutMerge(
result: WebpackPluginInstance[],
pluginConfig: UserPluginObjectConfig | DefaultPluginsIntersact
) {

const { instances, plugin, options } = pluginConfig

if (instances) {
for (const instanceKey in instances) {
const {
enabled = true, options
} = instances[instanceKey] as Exclude<PluginConfigInstance<any, any>, boolean>
enabled && result.push( new (plugin as any)(options) )
} = instances[instanceKey as keyof typeof instances] as Exclude<PluginConfigInstance<any, any>, boolean>
enabled && result.push( new plugin!(options) )
}

} else result.push( new (plugin as any)(options) )
} else result.push( new plugin!(options) )
}

const isEnabledByUserPlugin = (plugin: AllCaseUserPluginConfig) => (plugin as UserPluginObjectConfig).enabled !== false
Expand All @@ -43,7 +47,7 @@ function merge(defaultPlugins: DefaultPlugins, userPlugins: Plugins = {}) {
const defaultPluginConfig = defaultPlugins[defaultPluginKey as DefaultPluginsKeys]
const {
plugin, options, instances, enabled = true
} = defaultPluginConfig as UnionToIntersection<DefaultPlugins[DefaultPluginsKeys]>
} = defaultPluginConfig as DefaultPluginsIntersact


const userPluginConfig = userPlugins[defaultPluginKey as keyof Plugins] as AllCaseUserPluginConfig
Expand Down Expand Up @@ -73,16 +77,16 @@ function merge(defaultPlugins: DefaultPlugins, userPlugins: Plugins = {}) {
}
}

result.push( new (userPlugin as any)(finalPluginInstanceOptions) )
result.push( new userPlugin(finalPluginInstanceOptions) )
}
}

} else {
const finalPluginOptions = mergeOptions(options, userOptions, rewrite)
result.push( new (userPlugin as any)(finalPluginOptions) )
result.push( new userPlugin(finalPluginOptions) )
}

} else if (enabled) addWithoutMerge(result, defaultPluginConfig)
} else if (enabled) addWithoutMerge(result, defaultPluginConfig as DefaultPluginsIntersact)
}
}

Expand Down
9 changes: 5 additions & 4 deletions core/client_build/plugins/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ type DeepExclude<O1, O2> =



type AnyPlugin = abstract new (...args: any) => any
type AnyPlugin = new (...args: any) => any
type AnyPluginInstance = Exclude<PluginConfigInstance<any, any>, boolean>
type AnyPluginInstances = Record<string, AnyPluginInstance>
type AllCaseUserPluginConfig = UserPlugin<AnyPlugin, {}, {}, {}, {}>
type AllCaseUserPluginConfig = UserPlugin<AnyPlugin, object, object, AnyPluginInstances, object>
type UserPluginObjectConfig = Exclude<AllCaseUserPluginConfig, boolean>


type PluginConfigBase<_Plugin, _DefaultOptions> = {
plugin: _Plugin
enabled?: boolean
} & (_DefaultOptions extends null ? {} : { rewrite?: boolean })
} & (_DefaultOptions extends null ? object : { rewrite?: boolean })

type PluginConfigOptions<
_PluginOpts,
Expand Down Expand Up @@ -232,12 +232,13 @@ type DefaultPlugins = {
}
}
type DefaultPluginsKeys = keyof DefaultPlugins
type DefaultPluginsIntersact = UnionToIntersection<DefaultPlugins[DefaultPluginsKeys]>



export type {
CompressionInstanceCommonOptions, CopyWebpackPluginOptions,
DefaultPlugins, DefaultPluginsKeys, Plugins, PluginConfigInstance,
DefaultPlugins, DefaultPluginsKeys, DefaultPluginsIntersact, Plugins, PluginConfigInstance,
AllCaseUserPluginConfig, UserPluginObjectConfig,
DefaultEslintPluginOptions, DefaultHtmlPluginOptions
}
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {


const config = typeScriptEslintCreateConfig(
{ ignores: [ 'dist', 'node_modules', 'lib', '**/*.d.ts' ] },
{ ignores: [ 'dist', 'node_modules', 'lib' ] },
{
extends: [
...typeScriptLintConfigs.recommendedTypeChecked,
Expand Down
6 changes: 3 additions & 3 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type UnionToIntersection<U> = (
* @param T - object to iterate over
*/
type DeepPartial<T> = T extends object
? T extends Function
? T extends AnyFunc
? T
: { [P in keyof T]?: DeepPartial<T[P]> }
: T
Expand Down Expand Up @@ -125,13 +125,13 @@ type Never<O extends Obj> = {
* Extracts only object's required properties keys
* @param O - object
*/
type RequiredKeys<O> = { [K in keyof O]-?: {} extends Pick<O, K> ? never : K }[keyof O]
type RequiredKeys<O> = { [K in keyof O]-?: object extends Pick<O, K> ? never : K }[keyof O]

/**
* Extracts only object's optional properties keys
* @param O - object
*/
type OptionalKeys<O> = { [K in keyof O]-?: {} extends Pick<O, K> ? K : never }[keyof O]
type OptionalKeys<O> = { [K in keyof O]-?: object extends Pick<O, K> ? K : never }[keyof O]

/**
* Exclude null and undefined from a properties of a given object
Expand Down
Loading

0 comments on commit 0ebb5e4

Please sign in to comment.