`typescript/sync`: tuples and type literals from `checker.typeToTypeNode` print multi-line (SingleLine flag lost)
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 53/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, typescript
调研方向
Start with the typescript/sync API's checker.typeToTypeNode and api.printer.printNode path, then inspect dist/api/node/encoder.generated.js and how getNodeCommonData encodes multiLine. Compare the emitted node flags with the classic API behavior for tuple and inline object types. Done means the provided reproduction prints [Date, number] and { a: string; } on one line through typescript/sync.
由索引模型根据 Issue 内容生成。
描述
🔎 Search Terms
typeToTypeNode multiline, printNode single line, EmitFlags SingleLine api, typescript/sync printer, typeToTypeNode tuple printed on several lines
🕗 Version & Regression Information
- This changed between versions 6.0.2 (classic API) and 7.1.0-dev.20261027.1 (
typescript/sync, gitHead 49e69830) - not the same as #64429 - that one asks for
setEmitFlagson nodes the caller builds. here the checker builds the nodes, and the 6.0 node builder marks them single-line itself
⏯ Playground Link
n/a - needs the typescript/sync API
💻 Code
// input.ts
export type Shape = { tuple: [Date, number]; obj: { a: string } };
// repro.mjs - node 24.18, [email protected]
import path from 'node:path';
import { API } from 'typescript/sync';
const entry = path.resolve('input.ts');
const api = new API({ cwd: process.cwd() });
const program = api.createProgram([entry], { strict: true });
const checker = program.getProject().checker;
const sourceFile = program.getSourceFile(entry);
const alias = sourceFile.statements.find(s => s.name?.text === 'Shape');
const shape = checker.getDeclaredTypeOfSymbol(checker.getSymbolAtLocation(alias.name));
for (const prop of checker.getPropertiesOfType(shape)) {
const type = checker.getTypeOfSymbol(prop);
const node = checker.typeToTypeNode(type, sourceFile, 0);
console.log(`--- ${prop.name}`);
console.log('printNode:');
console.log(api.printer.printNode(node));
console.log(`typeToString: ${checker.typeToString(type)}`);
}
api.close();
🙁 Actual behavior
--- tuple
printNode:
[
Date,
number
]
typeToString: [Date, number]
--- obj
printNode:
{
a: string;
}
typeToString: { a: string; }
the same script on 6.0.2 (ts.createProgram, ts.createPrinter().printNode(ts.EmitHint.Unspecified, node, sourceFile)) prints [Date, number] and { a: string; }
🙂 Expected behavior
printNode gives [Date, number] and { a: string; } on one line, like 6.0 and like typeToString
Additional information about the issue
we generate a big .ts file of request/response types from typeToTypeNode output and are moving the generator from the 6.0 API to typescript/sync. this is the one difference we can't work around - every tuple and inline object type from the checker now takes several lines, and on one of our services ~14.5k of the 16k lines of the generated file change
as far as we can see the node encoder only sends multiLine for blocks and object/array literals (getNodeCommonData in dist/api/node/encoder.generated.js), and PrintNodeOptions only has preserveSourceNewlines, neverAsciiEscape and terminateUnterminatedLiterals, so the client can't ask for single-line. keeping the node builder's single-line flag on these nodes, or a printer option, would both do it for us
- 主要语言
- Go
- 星标
- 112k
- 派生
- 15.4k
- 平均合并
- 2 天 21 小时
- 30 天内合并 PR
- 126
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/TypeScript 的其他 Issue
-
Won't Fix
难度 2/5 1-3 小时 新手友好度 62/100
microsoft/TypeScript#65107 · 1 条评论 ·
维护者通常 1 天内回复
-
Native API: formatDiagnosticsWithColorAndContext drops related information without a file location可能已有人在做 @timurzvural 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/TypeScript#65087 ·
维护者通常 1 天内回复
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'可能重新可做 关联的 PR 已关闭且未合并。 未关闭Bug
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/TypeScript#64758 ·
维护者通常 1 天内回复
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`可能已有人在做 @rajnish-verma-22172 于 13 天前认领。 未关闭Bug
难度 2/5 1-3 小时 新手友好度 76/100
microsoft/TypeScript#64742 · 1 条评论 ·
维护者通常 1 天内回复
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindings可能已有人在做 @dmety 于 26 天前认领。 未关闭Bug
难度 2/5 1-3 小时 新手友好度 68/100
microsoft/TypeScript#64661 ·
维护者通常 1 天内回复
查看 microsoft/TypeScript 的全部 Issue
相似的 Issue
-
needs-area
难度 2/5 1-3 小时 新手友好度 68/100
Azure/typespec-azure#5936 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 72/100
github/gh-actions-lock#261 ·
维护者通常 1 天内回复
-
bug documentation
难度 2/5 1-3 小时 新手友好度 72/100
labmonkeys-space/nl6#974 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100