Skip to content

Commit 77530be

Browse files
authored
Merge pull request #2829 from themeum/v4-type-error
✨ Improve config type definitions and assertions
2 parents f70e24f + 029b021 commit 77530be

4 files changed

Lines changed: 19 additions & 16 deletions

File tree

assets/core/ts/config/config.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
const defaultTutorConfig = {
23
ID: 0,
34
ajaxurl: '',
@@ -35,13 +36,13 @@ const defaultTutorConfig = {
3536
tutor_pn_vapid_key: '',
3637
tutor_pn_client_id: '',
3738
tutor_pn_subscription_saved: '',
38-
difficulty_levels: [],
39-
supported_video_sources: [],
40-
edd_products: [],
41-
bp_groups: [],
42-
timezones: {},
43-
addons_data: [],
44-
kids_icons_registry: [],
39+
difficulty_levels: [] as any[],
40+
supported_video_sources: [] as any[],
41+
edd_products: [] as any[],
42+
bp_groups: [] as any[],
43+
timezones: {} as Record<string, any>,
44+
addons_data: [] as any[],
45+
kids_icons_registry: [] as any[],
4546
is_kids_mode: false,
4647
user_preferences: {
4748
auto_play_next: false,
@@ -66,10 +67,10 @@ const defaultTutorConfig = {
6667
user_status: '',
6768
display_name: '',
6869
},
69-
caps: {},
70+
caps: {} as Record<string, any>,
7071
cap_key: '',
71-
roles: [],
72-
allcaps: {},
72+
roles: [] as any[],
73+
allcaps: {} as Record<string, any>,
7374
filter: null,
7475
},
7576
settings: {
@@ -108,7 +109,8 @@ const defaultTutorConfig = {
108109
},
109110
};
110111

111-
export const tutorConfig = window._tutorobject || defaultTutorConfig;
112+
export const tutorConfig = (window._tutorobject || defaultTutorConfig) as typeof defaultTutorConfig &
113+
Record<string, any>;
112114
window.ajaxurl = tutorConfig.ajaxurl;
113115

114116
const config = {

assets/core/ts/declaration.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ declare global {
110110
quicktags?: unknown;
111111

112112
// Tutor object from PHP (extend existing type, don't redeclare)
113-
_tutorobject?: Record<string, unknown> & {
113+
_tutorobject?: Record<string, any> & {
114114
nonce_key?: string;
115115
ajaxurl?: string;
116116
tutor_url?: string;

assets/src/js/v3/@types/index.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,9 @@ declare global {
188188
enable_tax: boolean;
189189
enable_individual_tax_control: boolean;
190190
is_tax_included_in_price: boolean;
191-
pagination_per_page: string;
192-
quiz_attempts_allowed: string;
191+
pagination_per_page: string | number;
192+
quiz_attempts_allowed: string | number;
193+
has_active_membership_plans: boolean;
193194
};
194195
tutor_currency: {
195196
symbol: string;

assets/src/js/v3/shared/config/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ const defaultTutorConfig = {
112112
},
113113
};
114114

115-
export const tutorConfig = (window._tutorobject ||
116-
defaultTutorConfig) as unknown as typeof defaultTutorConfig as typeof defaultTutorConfig & Record<string, any>;
115+
export const tutorConfig = (window._tutorobject || defaultTutorConfig) as typeof defaultTutorConfig &
116+
Record<string, any>;
117117
window.ajaxurl = tutorConfig.ajaxurl;
118118

119119
const config = {

0 commit comments

Comments
 (0)