11import { renderContent } from '@/content-render/index'
22import Page from '@/frame/lib/page'
33import { TitleFromAutotitleError } from '@/content-render/unified/rewrite-local-links'
4- import type { Context } from '@/types'
4+ import type { Context , Page as PageType } from '@/types'
55
66export class EmptyTitleError extends Error { }
77
@@ -31,8 +31,8 @@ export class LiquidError extends Error {
3131interface RenderOptions {
3232 throwIfEmpty ?: boolean
3333 textOnly ?: boolean
34- cache ?: boolean | ( ( template : string , context : any ) => string )
35- [ key : string ] : any
34+ cache ?: boolean | ( ( template : string , context : Context ) => string )
35+ [ key : string ] : unknown
3636}
3737
3838const LIQUID_ERROR_NAMES = new Set ( [ 'RenderError' , 'ParseError' , 'TokenizationError' ] )
@@ -117,9 +117,10 @@ export function createTranslationFallbackComment(error: Error, property: string)
117117// higher level than `lib/`) how to use the URL to figure out the
118118// equivalent English page instance.
119119export async function renderContentWithFallback (
120- // Using `any` type for page because the actual Page class from @/frame/lib/page
121- // has more properties than the Page interface defined in @/types, causing type conflicts
122- page : any ,
120+ // Typed as the @/types Page interface (not the Page class) for caller
121+ // compatibility. The runtime contract is stricter: the value must be an
122+ // actual Page instance (enforced by the `page instanceof Page` check below).
123+ page : PageType ,
123124 property : string ,
124125 context : Context ,
125126 options ?: RenderOptions ,
@@ -130,7 +131,7 @@ export async function renderContentWithFallback(
130131 if ( typeof property !== 'string' ) {
131132 throw new Error ( `The second argument has to be a string (not ${ typeof property } )` )
132133 }
133- const template = ( page as any ) [ property ] as string
134+ const template = ( page as unknown as Record < string , string > ) [ property ]
134135 try {
135136 const output = await renderContent ( template , context , options )
136137 if ( options && options . throwIfEmpty && ! output . trim ( ) ) {
@@ -142,7 +143,7 @@ export async function renderContentWithFallback(
142143 // on English for.
143144 if ( isFallbackableError ( error ) && context . getEnglishPage ) {
144145 const enPage = context . getEnglishPage ( context )
145- const englishTemplate = ( enPage as any ) [ property ] as string
146+ const englishTemplate = ( enPage as unknown as Record < string , string > ) [ property ]
146147 // If you don't change the context, it'll confuse the liquid plugins
147148 // like `data.ts` that uses `environment.scope.currentLanguage`
148149 const enContext = Object . assign ( { } , context , { currentLanguage : 'en' } )
0 commit comments