TypeStrong / ts-loader

TypeScript loader for webpack
https://johnnyreilly.com/ts-loader-goes-webpack-5
MIT License
3.46k stars 431 forks source link

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

Open gepz opened 2 years ago

gepz commented 2 years ago

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.

johnnyreilly commented 2 years ago

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.

gepz commented 2 years ago

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?

johnnyreilly commented 2 years ago

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

cjdell commented 1 year ago

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.

johnnyreilly commented 1 year ago

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

cjdell commented 1 year ago

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.

johnnyreilly commented 1 year ago

No worries!

cjdell commented 1 year ago

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

cjdell commented 1 year ago

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

johnnyreilly commented 1 year ago

I hope you're satisfies @cjdell 😅