Skip to content

packages/cli 生成的临时 app 自带 strict + noUnusedLocals 的 tsconfig,但从来没有任何东西跑过 tsc —— 产物里有一批 TS 错(未用 import、隐式 any) #3853

Description

@yinlianghui

越界发现,记录于 #3827 实施期间(核实生成产物 import/声明对应关系时顺手跑了一次 tsc)。#3827 的面是清单声明与版本区间,这一条是生成的 TS 源码本身,故只记录。

事实(对 origin/main @ 844d17fc9 实测)

packages/cli/src/utils/app-generator.ts 两个生成器都写出这份 tsconfig.json:

strict: true,
noUnusedLocals: true,
noUnusedParameters: true,

而生成的源码过不了它。把 createTempAppWithRouting 生成到一个目录再用它自己的 tsconfig 跑 tsc -p tsconfig.json,与模块解析无关的错(即与 @object-ui/* 是否装上无关的那些)如下:

src/App.tsx(1,40):   error TS6133: 'Link' is declared but its value is never read.
src/Layout.tsx(7,3): error TS6133: 'cn' is declared but its value is never read.
src/Layout.tsx(8,3): error TS6133: 'Button' is declared but its value is never read.
src/Layout.tsx(20,3): error TS6133: 'SidebarGroupContent' is declared but its value is never read.
src/Layout.tsx(21,3): error TS6133: 'SidebarGroupLabel' is declared but its value is never read.
src/Layout.tsx(36,24): error TS7031: Binding element 'name' implicitly has an 'any' type.
src/Layout.tsx(36,30): error TS7031: Binding element 'className' implicitly has an 'any' type.
src/Layout.tsx(79,22): error TS7031: Binding element 'app' implicitly has an 'any' type.
src/Layout.tsx(79,27): error TS7031: Binding element 'children' implicitly has an 'any' type.
src/Layout.tsx(101,26): error TS7006: Parameter 'item' implicitly has an 'any' type.
src/Layout.tsx(101,32): error TS7006: Parameter 'idx' implicitly has an 'any' type.
src/Layout.tsx(104,56): error TS7006: Parameter 'child' implicitly has an 'any' type.

两类:

  1. 声明了没用的 import(TS6133):App.tsxLinkreact-router-dom 拿进来但只在 Layout.tsx 里用;Layout.tsx@object-ui/components 一次拿 24 个名字,其中 cn / Button / SidebarGroupContent / SidebarGroupLabel 四个没用上。
  2. 隐式 any(TS7031/TS7006):DynamicIconAppLayout 的 props 解构、以及 menu.map / children.map 的回调参数都没标类型,在 strict 下即错。

另有 src/theme-provider.tsxReact.ReactNode 作类型但只 import { createContext, useContext, useEffect, useState } from "react",没有把 React 作为命名空间引入 —— 模块里引用 UMD 全局命名空间需要 allowUmdGlobalAccess,生成的 tsconfig 没开。这条我没能在同一次 tsc 里干净地隔离出来(那次运行里 @object-ui/* 的类型没解析成功,噪音盖住了),所以标注为待核,不作为已证事实。

影响:今天没有东西是红的(故打 finding)

可选方向(不预设结论)

  1. 把生成源码改到能过自己的 tsconfig(补类型标注、删掉没用的 import),并在生成产物测试里加一道真 tsc —— 最彻底,也和 packages/cli 的 createTempAppWithRouting 生成的 app import 了未声明的 lucide-react,且其工具链区间落后仓内一到三个 major #3827 刚落的"生成产物用结构性闸门钉住"同取向。
  2. 只删没用的 import(TS6133 那五条),隐式 any 另开。
  3. 反过来把生成的 tsconfig 放松到与产物一致(去掉 noUnusedLocals / 降 strict)。最省事,但这是把 declared 往 enforced 的反方向调,与仓内 contract-first 的取向相反,我不倾向。

倾向方向 1;若嫌一次性太大,方向 2 + 隐式 any 单独排队也说得通。


Generated by Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions