-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
tsc, tsserver: hangs with large union type and object spread in React HOC (strict mode) #29949
Comments
With
With |
@RyanCavanaugh With I do have I tweaked the example to remove compilation errors: import * as React from "react";
const animated: {
[Tag in keyof JSX.IntrinsicElements]: React.ForwardRefExoticComponent<
React.ComponentPropsWithRef<Tag>
>
} = {} as any;
function makeAnimated<T extends React.ReactType>(
_comp: T
): React.ForwardRefExoticComponent<React.ComponentPropsWithRef<T>> {
return null as any; // not important
}
export interface UpgradedProps {
show: boolean;
}
export function test<P>(
component: React.ComponentType<P> | keyof React.ReactHTML
): any {
// --> changing to `const Comp: any` un-hangs tsserver <--
const Comp =
typeof component === "string"
? animated[component]
: makeAnimated(component);
return React.forwardRef<any, P & UpgradedProps>((props, ref) => {
const { show, ...ownProps } = props;
return show ? <Comp {...ownProps} ref={ref} /> : null;
});
} |
Here is my {
"compileOnSave": false,
"compilerOptions": {
"importHelpers": true,
"jsx": "react",
"lib": [
"dom",
"es5",
"es2015.collection",
"es2015.iterable",
"es2015.promise",
"es2015.symbol"
],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"preserveConstEnums": true,
"preserveSymlinks": true,
"removeComments": false,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es5"
}
} |
@RyanCavanaugh I just disabled all options and re-enabled one-by-one. The server will hang when {
"compileOnSave": false,
"compilerOptions": {
"jsx": "react",
"skipLibCheck": true,
"strict": true
}
} |
There's the trick! Thank you |
Pretty sure this is to do with type string genaration. |
Looks like the specific |
I created this a few days ago without doing much investigation, but just today discovered that it is caused by |
Maybe - #30411 may also help. Spent some time looking at this the other day, though (and talking about it in our design meeting) - ultimately the |
@weswigham Function refs do not have a interface RefObject<T> {
readonly current: T | null;
}
type Ref<T> = { bivarianceHack(instance: T | null): void }["bivarianceHack"] | RefObject<T> | null;
interface RefAttributes<T> extends Attributes {
ref?: Ref<T>;
} Or is there some other definition you are referring to where they do overlap? |
They don't define one, however as written a |
Ah, makes sense, thank you for the explanation! |
is there any other solutions or workarounds for this?
fixed it |
#42772 may still be valuable enough to revive at some point if operating close to our limits is truly common, but we've already done a lot of recentish work to defer/simplify unions like these wherever possible, and minimally, we should issue a complexity error rather than hang nowadays. |
TypeScript Version: 3.4.0-dev.20190216
Search Terms: hang higher order union strictFunctionTypes
Code
Note that this code has compilation errors, but that's not important. When invoking
tsc
or loading in an editor that usestsserver
, the compilation hangs/never completes.Expected behavior:
Compilation completes (optionally with errors).
Actual behavior:
Compilation hangs.
Repro Link: https://github.com/jgoz/typescript-bug
Related Issues: Didn't find anything recent
The text was updated successfully, but these errors were encountered: