Open sethp opened 3 months ago
It can be simplified further to:
(await
WebAssembly.instantiateStreaming(fetch("")));
export class BitSet {}
This is a weird bug - or how I call it: a fun issue š
Or even
(await
0);
export let aaa = 1;
export let bbb = 2;
I'm guessing that for whatever reason, we are trying to re-bind the last statement of a file which conflicts with the same existing symbol in the symbol table.
It's an issue with reparseTopLevelAwait
(or the data that it operates on)
š Search Terms
typescript top-level await export class "duplicate identifier"
š Version & Regression Information
āÆ 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
š 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: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 againsttsc
here.Thanks for all your work on Typescript!