|
| 1 | +//// [tests/cases/compiler/genericCallInferenceInConditionalTypes1.ts] //// |
| 2 | + |
| 3 | +=== genericCallInferenceInConditionalTypes1.ts === |
| 4 | +// https://github.com/microsoft/TypeScript/issues/59937 |
| 5 | + |
| 6 | +type Ref<T> = { |
| 7 | +>Ref : Symbol(Ref, Decl(genericCallInferenceInConditionalTypes1.ts, 0, 0)) |
| 8 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 2, 9)) |
| 9 | + |
| 10 | + current: T; |
| 11 | +>current : Symbol(current, Decl(genericCallInferenceInConditionalTypes1.ts, 2, 15)) |
| 12 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 2, 9)) |
| 13 | + |
| 14 | +}; |
| 15 | + |
| 16 | +type FunctionComponent<P> = (props: P) => unknown; |
| 17 | +>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2)) |
| 18 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 23)) |
| 19 | +>props : Symbol(props, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 29)) |
| 20 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 23)) |
| 21 | + |
| 22 | +type ComponentProps<T extends FunctionComponent<any>> = |
| 23 | +>ComponentProps : Symbol(ComponentProps, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 50)) |
| 24 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 8, 20)) |
| 25 | +>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2)) |
| 26 | + |
| 27 | + T extends FunctionComponent<infer P> ? P : {}; |
| 28 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 8, 20)) |
| 29 | +>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2)) |
| 30 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 9, 35)) |
| 31 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 9, 35)) |
| 32 | + |
| 33 | +type PropsWithoutRef<P> = P extends any |
| 34 | +>PropsWithoutRef : Symbol(PropsWithoutRef, Decl(genericCallInferenceInConditionalTypes1.ts, 9, 48)) |
| 35 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 11, 21)) |
| 36 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 11, 21)) |
| 37 | + |
| 38 | + ? "ref" extends keyof P |
| 39 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 11, 21)) |
| 40 | + |
| 41 | + ? Omit<P, "ref"> |
| 42 | +>Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) |
| 43 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 11, 21)) |
| 44 | + |
| 45 | + : P |
| 46 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 11, 21)) |
| 47 | + |
| 48 | + : P; |
| 49 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 11, 21)) |
| 50 | + |
| 51 | +type ComponentPropsWithoutRef<T extends FunctionComponent<any>> = |
| 52 | +>ComponentPropsWithoutRef : Symbol(ComponentPropsWithoutRef, Decl(genericCallInferenceInConditionalTypes1.ts, 15, 6)) |
| 53 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 17, 30)) |
| 54 | +>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2)) |
| 55 | + |
| 56 | + PropsWithoutRef<ComponentProps<T>>; |
| 57 | +>PropsWithoutRef : Symbol(PropsWithoutRef, Decl(genericCallInferenceInConditionalTypes1.ts, 9, 48)) |
| 58 | +>ComponentProps : Symbol(ComponentProps, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 50)) |
| 59 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 17, 30)) |
| 60 | + |
| 61 | +declare function forwardRef<T, P>( |
| 62 | +>forwardRef : Symbol(forwardRef, Decl(genericCallInferenceInConditionalTypes1.ts, 18, 37)) |
| 63 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 28)) |
| 64 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 30)) |
| 65 | + |
| 66 | + component: (props: P, ref: Ref<T>) => unknown, |
| 67 | +>component : Symbol(component, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 34)) |
| 68 | +>props : Symbol(props, Decl(genericCallInferenceInConditionalTypes1.ts, 21, 14)) |
| 69 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 30)) |
| 70 | +>ref : Symbol(ref, Decl(genericCallInferenceInConditionalTypes1.ts, 21, 23)) |
| 71 | +>Ref : Symbol(Ref, Decl(genericCallInferenceInConditionalTypes1.ts, 0, 0)) |
| 72 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 28)) |
| 73 | + |
| 74 | +): (props: P & { ref?: Ref<T> }) => unknown; |
| 75 | +>props : Symbol(props, Decl(genericCallInferenceInConditionalTypes1.ts, 22, 4)) |
| 76 | +>P : Symbol(P, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 30)) |
| 77 | +>ref : Symbol(ref, Decl(genericCallInferenceInConditionalTypes1.ts, 22, 16)) |
| 78 | +>Ref : Symbol(Ref, Decl(genericCallInferenceInConditionalTypes1.ts, 0, 0)) |
| 79 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 20, 28)) |
| 80 | + |
| 81 | +const ComponentWithForwardRef = forwardRef( |
| 82 | +>ComponentWithForwardRef : Symbol(ComponentWithForwardRef, Decl(genericCallInferenceInConditionalTypes1.ts, 24, 5)) |
| 83 | +>forwardRef : Symbol(forwardRef, Decl(genericCallInferenceInConditionalTypes1.ts, 18, 37)) |
| 84 | + |
| 85 | + <T extends FunctionComponent<any>>( |
| 86 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 25, 3)) |
| 87 | +>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2)) |
| 88 | + |
| 89 | + props: ComponentPropsWithoutRef<T>, |
| 90 | +>props : Symbol(props, Decl(genericCallInferenceInConditionalTypes1.ts, 25, 37)) |
| 91 | +>ComponentPropsWithoutRef : Symbol(ComponentPropsWithoutRef, Decl(genericCallInferenceInConditionalTypes1.ts, 15, 6)) |
| 92 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 25, 3)) |
| 93 | + |
| 94 | + ref: Ref<HTMLElement>, |
| 95 | +>ref : Symbol(ref, Decl(genericCallInferenceInConditionalTypes1.ts, 26, 39)) |
| 96 | +>Ref : Symbol(Ref, Decl(genericCallInferenceInConditionalTypes1.ts, 0, 0)) |
| 97 | +>HTMLElement : Symbol(HTMLElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) |
| 98 | + |
| 99 | + ) => { |
| 100 | + return null; |
| 101 | + }, |
| 102 | +); |
| 103 | + |
| 104 | +type Test<T> = T extends { component?: infer Component } |
| 105 | +>Test : Symbol(Test, Decl(genericCallInferenceInConditionalTypes1.ts, 31, 2)) |
| 106 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 33, 10)) |
| 107 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 33, 10)) |
| 108 | +>component : Symbol(component, Decl(genericCallInferenceInConditionalTypes1.ts, 33, 26)) |
| 109 | +>Component : Symbol(Component, Decl(genericCallInferenceInConditionalTypes1.ts, 33, 44)) |
| 110 | + |
| 111 | + ? Component extends FunctionComponent<any> |
| 112 | +>Component : Symbol(Component, Decl(genericCallInferenceInConditionalTypes1.ts, 33, 44)) |
| 113 | +>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2)) |
| 114 | + |
| 115 | + ? ComponentProps<Component> |
| 116 | +>ComponentProps : Symbol(ComponentProps, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 50)) |
| 117 | +>Component : Symbol(Component, Decl(genericCallInferenceInConditionalTypes1.ts, 33, 44)) |
| 118 | + |
| 119 | + : never |
| 120 | + : never; |
| 121 | + |
| 122 | +// the first one here has a chance to pollute the cache |
| 123 | +type Result1 = ComponentProps<typeof ComponentWithForwardRef>; |
| 124 | +>Result1 : Symbol(Result1, Decl(genericCallInferenceInConditionalTypes1.ts, 37, 10)) |
| 125 | +>ComponentProps : Symbol(ComponentProps, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 50)) |
| 126 | +>ComponentWithForwardRef : Symbol(ComponentWithForwardRef, Decl(genericCallInferenceInConditionalTypes1.ts, 24, 5)) |
| 127 | + |
| 128 | +// that could be incorrectly reused by this one |
| 129 | +type Result2 = Test<{ component: typeof ComponentWithForwardRef }>; // no `T` leak |
| 130 | +>Result2 : Symbol(Result2, Decl(genericCallInferenceInConditionalTypes1.ts, 40, 62)) |
| 131 | +>Test : Symbol(Test, Decl(genericCallInferenceInConditionalTypes1.ts, 31, 2)) |
| 132 | +>component : Symbol(component, Decl(genericCallInferenceInConditionalTypes1.ts, 42, 21)) |
| 133 | +>ComponentWithForwardRef : Symbol(ComponentWithForwardRef, Decl(genericCallInferenceInConditionalTypes1.ts, 24, 5)) |
| 134 | + |
| 135 | +// same as ComponentWithForwardRef above but using a resolved signature instead of a direct inferred result of `forwardRef` |
| 136 | +declare const ComponentWithForwardRef2: <T extends FunctionComponent<any>>( |
| 137 | +>ComponentWithForwardRef2 : Symbol(ComponentWithForwardRef2, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 13)) |
| 138 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 41)) |
| 139 | +>FunctionComponent : Symbol(FunctionComponent, Decl(genericCallInferenceInConditionalTypes1.ts, 4, 2)) |
| 140 | + |
| 141 | + props: PropsWithoutRef<ComponentProps<T>> & { |
| 142 | +>props : Symbol(props, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 75)) |
| 143 | +>PropsWithoutRef : Symbol(PropsWithoutRef, Decl(genericCallInferenceInConditionalTypes1.ts, 9, 48)) |
| 144 | +>ComponentProps : Symbol(ComponentProps, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 50)) |
| 145 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 41)) |
| 146 | + |
| 147 | + className?: string; |
| 148 | +>className : Symbol(className, Decl(genericCallInferenceInConditionalTypes1.ts, 46, 47)) |
| 149 | + |
| 150 | + as?: T | undefined; |
| 151 | +>as : Symbol(as, Decl(genericCallInferenceInConditionalTypes1.ts, 47, 23)) |
| 152 | +>T : Symbol(T, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 41)) |
| 153 | + |
| 154 | + } & { |
| 155 | + ref?: Ref<HTMLElement> | undefined; |
| 156 | +>ref : Symbol(ref, Decl(genericCallInferenceInConditionalTypes1.ts, 49, 7)) |
| 157 | +>Ref : Symbol(Ref, Decl(genericCallInferenceInConditionalTypes1.ts, 0, 0)) |
| 158 | +>HTMLElement : Symbol(HTMLElement, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) |
| 159 | + |
| 160 | + }, |
| 161 | +) => unknown; |
| 162 | + |
| 163 | +type Result3 = ComponentProps<typeof ComponentWithForwardRef2>; |
| 164 | +>Result3 : Symbol(Result3, Decl(genericCallInferenceInConditionalTypes1.ts, 52, 13)) |
| 165 | +>ComponentProps : Symbol(ComponentProps, Decl(genericCallInferenceInConditionalTypes1.ts, 6, 50)) |
| 166 | +>ComponentWithForwardRef2 : Symbol(ComponentWithForwardRef2, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 13)) |
| 167 | + |
| 168 | +type Result4 = Test<{ component: typeof ComponentWithForwardRef2 }>; |
| 169 | +>Result4 : Symbol(Result4, Decl(genericCallInferenceInConditionalTypes1.ts, 54, 63)) |
| 170 | +>Test : Symbol(Test, Decl(genericCallInferenceInConditionalTypes1.ts, 31, 2)) |
| 171 | +>component : Symbol(component, Decl(genericCallInferenceInConditionalTypes1.ts, 55, 21)) |
| 172 | +>ComponentWithForwardRef2 : Symbol(ComponentWithForwardRef2, Decl(genericCallInferenceInConditionalTypes1.ts, 45, 13)) |
| 173 | + |
0 commit comments