-
-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't recognize "const" and generic. #53
Comments
Thanks for this issue @olegKusov Do you mind providing more details? For example, your Webpack config. A minimal reproduction, preferably. Also, this isn't valid JS: fn() => {const = ...} Do you mean to do something like: const fn = () => {
const a = ...;
} |
I'm facing the same issue, for example I get the const usePrevious = <T>(value: T) => {
const ref = useRef<T>();
useEffect(() => {
ref.current = value;
});
return ref.current;
};
export default usePrevious; |
@peek4y I added that exact code as a test-case to confirm that it works. |
Closing this as it seems resolved/stale. @olegKusov if your problem still persists, feel free to open a new ticket with more context. |
I think the issue here is if you set the loader to It would be nice if the loader could choose what to do based on file extension, but as a workaround, I set up separate rules for ts and tsx, with different loader configurations:
|
Ah true. I'm able to reproduce the bug with the code snippet in a tsx file. Seems this behavior is by TypeScripts spec and is known on esbuild's end (ref 1, ref 2).
It used to try to behave this way, but it's actually very difficult to determine the appropriate file type based on file name. For example, Vue SFC files have a Simply passing in I'll update the docs to recommend setting up two different rules for ts and tsx. Thanks! |
Update: Instead of making users add a rule for both ts and tsx, I added fallback logic so that it tries ts if tsx fails with a particular error: a713461 That way, you can continue to use the |
@privatenumber I believe I'm running into this same issue with v2.4.0, but the error I'm receiving is slightly different:
The Code in question is something like:
So it seems the error message may not be predictable! |
Thanks for reporting another repro. The fallback logic was added in 2.5.0 which was released just the other day so try seeing if that fixes it. If not, would you mind opening another issue for it? |
|
With 2.5.0, you should be able to just use |
@privatenumber I'll try to find some time to try to reproduce using 2.5.0. But I don't think I was clear with my initial report! You're correct that I was not using 2.5.0 when I reported the issue. But I reported it after looking at the code for the soon to be 2.5.0 (develop) branch. I saw that the fix there does not handle the case I found. @olegKusov yes, that is a workaround that I used as well! But since I noticed that the intention of the code is to gracefully fallback to TS mode in the event of a TSX failure, I figured reporting the exception I found was worthwhile. Thanks for the confirmation, regardless! |
Thanks @kirbysayshi. Fixed in 2.6.1 |
code: fn() => {const = ...}
error: Unexpected "const"
code: props: {[key in keyof T]: [Readonly<T[key]>, (v: T[key]) => void] }
error: Expected "]" but found "T"
The text was updated successfully, but these errors were encountered: