Skip to content

Commit 43d4611

Browse files
committed
fix(miniprogram-typescript): strict mode
1 parent 0e20469 commit 43d4611

File tree

1 file changed

+8
-5
lines changed
  • glass-easel-miniprogram-typescript/src

1 file changed

+8
-5
lines changed

glass-easel-miniprogram-typescript/src/server.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ type Properties<T> = _ComponentFieldTypes_<T> extends _Component_<infer P, any,
279279
? P
280280
: { [k: string]: any }`
281281
let usingComponentsImports = ''
282-
const usingComponensItems = [] as string[]
282+
const usingComponentsItems = [] as string[]
283283
const usingComponents = this.projectDirManager.getUsingComponents(compFullPath)
284284
Object.entries(usingComponents).forEach(([tagName, compPath]) => {
285285
const source = program.getSourceFile(`${compPath}.ts`)
@@ -289,24 +289,27 @@ type Properties<T> = _ComponentFieldTypes_<T> extends _Component_<infer P, any,
289289
const relPath = path.relative(compDir, compPath)
290290
const entryName = `_component_${tagName.replace(/-/g, '_')}`
291291
usingComponentsImports += `import type ${entryName} from './${escapeJsString(relPath)}'\n`
292-
usingComponensItems.push(`'${tagName}': Properties<typeof ${entryName}>;\n`)
292+
usingComponentsItems.push(`'${tagName}': Properties<typeof ${entryName}>;\n`)
293293
})
294294

295295
// treat generics as any type tags
296296
const generics = this.projectDirManager.getGenerics(compFullPath)
297297
generics.forEach((tagName) => {
298-
usingComponensItems.push(`'${tagName}': any;\n`)
298+
usingComponentsItems.push(`'${tagName}': any;\n`)
299299
})
300300

301301
// TODO handling placeholders
302302

303303
// compose tags types
304304
const unknownElementLine = this.options.strictMode
305-
? 'interface UnknownElement {}'
305+
? 'interface UnknownElement { _$fieldTypes: { propertyValues: Record<string, never>, dataWithProperties: Record<string, never>, methods: Record<string, never> } }'
306306
: 'type UnknownElement = { _$fieldTypes: null, [k: string]: any }'
307+
const otherComponents = this.options.strictMode
308+
? '[other: string]: unknown'
309+
: '[other: string]: { [k: string]: any }'
307310
const tagsLine = `
308311
declare const tags: {
309-
${usingComponensItems.join('')}[other: string]: { [k: string]: any } }`
312+
${usingComponentsItems.join('')}${otherComponents} }`
310313

311314
// add an empty export to avoid some tsc behavior
312315
const exportLine = 'export default {}'

0 commit comments

Comments
 (0)