-
Notifications
You must be signed in to change notification settings - Fork 4.8k
taro-cli新增支持可动态扩展ask导航步骤 #17715
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
base: main
Are you sure you want to change the base?
taro-cli新增支持可动态扩展ask导航步骤 #17715
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -43,6 +43,7 @@ export interface IProjectConf { | |||||||||||||||||||||||||||||||||
hideDefaultTemplate?: boolean | ||||||||||||||||||||||||||||||||||
framework: FrameworkType | ||||||||||||||||||||||||||||||||||
compiler?: CompilerType | ||||||||||||||||||||||||||||||||||
ask?: Function | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
type CustomPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; | ||||||||||||||||||||||||||||||||||
|
@@ -126,6 +127,14 @@ export default class Project extends Creator { | |||||||||||||||||||||||||||||||||
await this.askTemplate(conf, prompts, templates) | ||||||||||||||||||||||||||||||||||
const templateChoiceAnswer = await inquirer.prompt<IProjectConf>(prompts) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
// 导航步骤扩展 | ||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||
if (typeof conf.ask === 'function') { | ||||||||||||||||||||||||||||||||||
const { ask, ...other } = conf | ||||||||||||||||||||||||||||||||||
await conf.ask({ ...other, templatePath: this.templatePath(templateChoiceAnswer.template) }) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} catch (e) { } | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
Comment on lines
+130
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion 改进错误处理并确保类型安全 当前实现中有以下几个问题:
建议改进错误处理并确保类型安全。 // 导航步骤扩展
try {
if (typeof conf.ask === 'function') {
const { ask, ...other } = conf
- await conf.ask({ ...other, templatePath: this.templatePath(templateChoiceAnswer.template) })
+ await conf.ask({ ...other, templatePath: this.templatePath(templateChoiceAnswer.template) })
}
-} catch (e) { }
+} catch (e) {
+ console.log(chalk.yellow('执行导航步骤扩展时发生错误: '), e)
+} 📝 Committable suggestion
Suggested change
🧰 Tools🪛 ESLint[error] 133-133: 'ask' is assigned a value but never used. (@typescript-eslint/no-unused-vars) 🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||
return { | ||||||||||||||||||||||||||||||||||
...answers, | ||||||||||||||||||||||||||||||||||
...compilerAndTemplateSourceAnswer, | ||||||||||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不要使用
Function
作为类型避免使用
Function
作为类型声明,这无法提供类型安全性。建议定义具体的函数类型,明确指定参数和返回值类型。📝 Committable suggestion
🧰 Tools
🪛 Biome (1.9.4)
[error] 46-46: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
🪛 ESLint
[error] 46-46: Don't use
Function
as a type. TheFunction
type accepts any function-like value.It provides no type safety when calling the function, which can be a common source of bugs.
It also accepts things like class declarations, which will throw at runtime as they will not be called with
new
.If you are expecting the function to accept certain arguments, you should explicitly define the function shape.
(@typescript-eslint/ban-types)
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里补齐一下类型
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Single-Dancer 是的,我将补充具体的函数类型,替换掉泛型的
Function
类型:这个类型定义明确了: