Multi-line top-level `await` causes duplicate declaration error

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

Chưa có ai nhận issue này.

Đá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
45/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
typescript
Lĩnh vực
compilers

Hướng nghiên cứu

Bắt đầu với bản tái hiện được liên kết trong TypeScript Playground và điều tra phân tích top-level-await và module của compiler liên quan đến chẩn đoán BitSet trùng lặp đã được báo cáo. Hoàn tất khi mẫu không tạo ra lỗi định danh trùng lặp cũng như lỗi không tương thích của thành viên private, dù có hay không có khai báo module rỗng.

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

Mô tả

Bug Domain: Binder Help Wanted
🔎 Search Terms

typescript top-level await export class "duplicate identifier"

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about await, identifiers, modules
⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.0-dev.20240827#code/AYKAFAtg9gJgrgGwKYgJBgGZwHYGMAEYSAHgA5QBOALvgEQCWAbACwB05pu2VtAlIaQCGFQRHxNm-MBSQBnRDXoBmAEy8Q+TfgRRcghKwDmSGgAYNWieyiduFzcpWsA7iNIB9Cb3WgA9L-wAN3pBfAALKipSWQAuf2ckACNBWVkkCESEAE8jeiowuETWeihfZ0FEql8YdNLyqhVy2QhfEFwobFkaJrEAXkJBcry0AHUkgEFU9Myc+k6qQW4QqiQAZSoZUTnDMDRUDBNcMLBaGEEFmMFSUgR6PSoS7DKUiABuZLSWABpxgHEAMQAXokAIoAUXGkPGACFoYZ-oZxgANZjQjDOACyAGFxiDxgAJAAihjBAGlBAAVACapgAMthoYFcL8AHJwGBQrGGQywxGI-E4LHOcak6G-ACsYUSIwAqjjnBDIb1enwvnsAN4AX28rxAbQ6XXE80WuCQ+H6PWKxrwSF1JHI1Hw7Xm+A47RwNH6cy6JqQrHtlCosgA2gByKxu7ihgC6+BShECMXwiXohjmVH4vQAfPhsHAMkgKLqQAHHbgEClZPhoXlViZ8Or7PgAMSGChQZxgXhakCavX+fDQeDIfA4doQCBIbjuSfuKhQdwYejEBuaoA

💻 Code
`
(module
	(func (export "i64.popcnt") (param i64) (result i32)
    local.get 0
    i64.popcnt
    i32.wrap_i64))
`
// via https://webassembly.github.io/wabt/demo/wat2wasm/
const wasm = (await
	WebAssembly.instantiateStreaming(
		fetch("data:application/wasm;base64,AGFzbQEAAAABBgFgAX4BfwMCAQAHDgEKaTY0LnBvcGNudAAACggBBgAgAHunCwAKBG5hbWUCAwEAAA=="),
		{}));

const instance = wasm.instance;
export const popcount = instance.exports['i64.popcnt'] as (v: bigint) => number;

export class BitSet {
    #grow(){}
}

// module uncomment_me_to_fix {}
🙁 Actual behavior

Line 17 (export class BitSet) reports an error: Duplicate identifier 'BitSet'.(2300)

As far as I can see there's no duplicate identifier; suppressing that line with a @ts-expect-error produces a strange result that the exported BitSet is unusable when imported into a different module, whereupon Typescript reports:

Type 'import("./lib/bitset").BitSet' is not assignable to type 'import("./lib/bitset").BitSet'. Two different types with this name exist, but they are unrelated.
Property '#grow' in type 'BitSet' refers to a different member that cannot be accessed from within type 'BitSet'.ts(2719)

Uncommenting the empty module definition at the bottom of the file appears to collapse the superimposed wave function of BitSet, and renders the type singular again.

🙂 Expected behavior

To see neither error, whether or not there's a module in the same file.

Additional information about the issue

Hopefully, it's clear enough from the example what I'm hoping to do here with the top-level await; I deleted all the method bodies for brevity, so you'll have to trust me when I say popcount is a very useful primitive to have.

I did spend a fair bit of time looking for suggestions on whether I'm holding the tool wrong with the await ....; export class ... sequencing, but as far as I can tell that is how it's intended to be used. The fact that an unrelated (to my eye, anyway) expression later on in the file changes the compiler's report is what finally moved me to file an issue against tsc here.

Thanks for all your work on Typescript!

Ngôn ngữ chính
Go
Star
111k
Fork
14.4k
Merge trung bình
1 ngày 19 giờ
Pull request đã merge (30 ngày)
117

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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.