`typescript/sync`: tuples and type literals from `checker.typeToTypeNode` print multi-line (SingleLine flag lost)

Đang mở
#64,991 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@1-DARK đang làm issue này rồi.

Từ ngày 30/10/2026.

  • #65062 của @1-DARK — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
53/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
node.js, typescript

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Bug Domain: API
🔎 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 setEmitFlags on 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

Ngôn ngữ chính
Go
Star
112k
Fork
15.4k
Merge trung bình
2 ngày 21 giờ
Pull request đã merge (30 ngày)
126

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/TypeScript

Tất cả issue của microsoft/TypeScript

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.