ts-loader icon indicating copy to clipboard operation
ts-loader copied to clipboard

Bundle failure when export default "satisfies" any generic type, in Typescript 4.9.1-beta

Open gepz opened this issue 3 years ago • 10 comments

Expected Behaviour

Output file is bundled correctly.

Actual Behaviour

The output file index.js only contains the 2 lines of the compiled entry file without bundling anything.

(()=>{"use strict"
simpleWrap(mainComponent,void 0)})()

Steps to Reproduce the Problem

Import anything and use it in export default, Then add "satisfies Readonly" or satisfies any other generic type at the end

import mainComponent from '@/mainComponent';
import simpleWrap from '@/simpleWrap';

export default simpleWrap(
  mainComponent,
  undefined,
) satisfies Readonly<unknown>;

This only happens when export default satisfies a generic type, "satisfies unknown" or "satisfies () => void" work correctly.

Dependencies:

    "ts-loader": "^9.3.1",
    "typescript": "^4.9.1-beta",
    "webpack": "^5.74.0",
    "webpack-bundle-analyzer": "^4.6.1",
    "webpack-cli": "^4.10.0",
    "webpack-dev-server": "^4.10.1",

Location of a Minimal Repository that Demonstrates the Issue.

gepz avatar Sep 25 '22 03:09 gepz

It's likely this is a typescript issue rather than a ts-loader/webpack one. ts-loader uses the export from TSC - probably worth looking there first.

johnnyreilly avatar Sep 25 '22 05:09 johnnyreilly

I'm not sure how to reproduce this with tsc only. Does ts-loader/webpack use anything else from tsc other than the generated js and declaration files that can be obtained by running tsc cli?

gepz avatar Sep 25 '22 06:09 gepz

Just run tsc over your source files. It ships with the TypeScript npm package

johnnyreilly avatar Sep 25 '22 07:09 johnnyreilly

I encountered this issue when beginning to use the satisfies keyword for the first time in a WebPack project. I've narrowed it down to the smallest example of the bug occurring. Please see the following repo:

https://github.com/cjdell/ts-loader-satisfies-bug

Hope this is of help. Let me know if you want me to clarify anything. Also thank you to all contributors for giving this your valuable attention.

cjdell avatar Nov 24 '22 17:11 cjdell

Thanks for sharing a reproduction - I don't have bandwidth to look at it at present but I encourage others to do so. I'm surprised this is occurring as TSC should be stripping this

johnnyreilly avatar Nov 24 '22 17:11 johnnyreilly

Thanks @johnnyreilly. I actually have since narrowed it down further and I'm invoking the TS compile just as ts-loader does and it behaves the same way. Looks like a legitimate TS bug. Your instincts were correct. I will raise the issue on the TS repo. Thanks for replying so quickly.

cjdell avatar Nov 24 '22 19:11 cjdell

No worries!

johnnyreilly avatar Nov 24 '22 22:11 johnnyreilly

Link to the TypeScript issue for anyone following this: https://github.com/microsoft/TypeScript/issues/51642

cjdell avatar Nov 25 '22 14:11 cjdell

Looks like this will be fixed very shortly... :-) https://github.com/microsoft/TypeScript/pull/51704

cjdell avatar Dec 01 '22 12:12 cjdell

I hope you're satisfies @cjdell 😅

johnnyreilly avatar Dec 01 '22 14:12 johnnyreilly