Repository: TypeScript
Issue: Performance issues when using generic constraints
Labels: Needs Investigation

# Bug Report

Using generic constraints makes IntelliSense a bit slow, but applying the same constraint on a conditional type does not. 

### 🔎 Search Terms

constraints, generic constraints, conditional type constraints, intellisense, performance

### 🕗 Version & Regression Information

- This is the behavior in every version I tried, and I reviewed the FAQ for entries about constraints

### ⏯ Playground Link

[Playground / Using generic constraints](https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgIilQ3wG4BYAKCpgE8wk4AFHMAZwHVgYALAQTYAeFhHYAaOALhIAHjCQA7ACZtExGADoAogBskIRTAAq9JAD44AXmatVAMipw16TQGFckBYZHsuvCACuMMiYggIWdnAA3nAobAD8AFySqgC+FNSUdAxqykhQwrYSUrLyyqrILtp6BgrGphbWABSOcGC2yT6c3PxCXcVsZmKtRJjJlRgaAGLQAO4oUEpISiGCE24eEF51q+FmVACUVhbrGuu6+oZwAD5wCgE6Ohk0pnDu4FuGhaJsEgAiSEwKAeMBKckUKmckwutXqDEacEErTBZUhpxhhhMOWsAKBIIEVDMLUoTnaP06tj8vW+4hSEShmhCfBgMCgwAARkEkEJTu9PIZdoN9pQjpYTuozuoMXUbncHk8qFRZJBYHA0Fs2Fg5gsVoCrIj+nBccCdKDVKUIRUJdK4eZiU4iHkoOMIfkab8jYCTWbhaLxVVMNrFiEmo6llAjnE3pttjB3f8vfjBs9KMA6vkgWhGEZuTAutFWgA3BbAFB1JIEFD4WX4dnV274NBkKipRWUdUKTVwHNd6yBqDzYOAwQ9vNFAicllbfBEpp+xFKYCFuAAejMBxTI9zsTYlnwVbgPFGe5X1bXGSAA)

[Playground / Using conditional type constraints](https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgIilQ3wG4BYAKCpgE8wk4AFHMAZwHVgYALAQTYAeFhHYAaOAIB8cALyS2cJAA8YSAHYATRcnQwAdAFEANkhAaYAFXpIqcOAH5mrRQDJExAwGFckdRZF2Ll4IAFcYZExBaTh3AG84FDYHAC4FOABfOzg0-wA3JCgKako6BjgAcSQYH3AIf3UIpCiY+QElVQ1tDz0jU3NG6wZsp10MfVq-C0jotils3KQCoqoaGw8tQuEXCVa4AApssBc0wM5ufiEz3bmxbKJMNLGDADFoAHcUKE0kTRmqmq+erTZqzKTzSgASjkMme+meJjMFjgAB84OpQsZjMU1uVJsDGttRGwJAARZooTEwPazORwcmYSnGalzQ6UezHYmnFzBS5E8QKGTuOGRPgwGBQYAAI3CSCEAPxDSaLTmEOhslhnnhnkRA3gaIxWJxlBUkFgcDQ9TYWA+Xz+zTp-JJ9IpVOkbPsRE2UCeXS21xdjLdcyo6s1vUwtu+kX2Xp+UGhSTgiosTrJruZ0mNwEahUZaEYljlMDOcDi2TyX2AKEaqQIKHwqIIUsbaPwaDIVCyJUt6mtcCL-fkkagn2joMHJZ2zfCMHq+Ck+32Ybggk0wDycAA9FJIcbBJPEmxZPgG3AeA8T1vGzvikA)

### 💻 Code

Using generic constraints

<!-- Please post the relevant code sample here as well-->
```ts
import React from "react";

type PropsWithAs<Props, As extends React.ElementType> = Props &
  React.ComponentPropsWithoutRef<As> & { as?: As };

type Render<Props, As extends React.ElementType> = (
  props: PropsWithAs<Props, As>,
  ref: React.ForwardedRef<React.ComponentRef<As>>
) => React.ReactElement | null;

type Component<Props, DefaultAs extends React.ElementType> = <
  As extends React.ElementType = DefaultAs
>(
  props: PropsWithAs<Props, As> & React.RefAttributes<React.ComponentRef<As>>
) => React.ReactElement | null;

export const forwardRef = <Props, DefaultAs extends React.ElementType>(
  render: Render<Props, DefaultAs>
) => React.forwardRef(render) as Component<Props, DefaultAs>;

interface TestProps {
  variant?: "a" | "b" | "c";
}

const Test = forwardRef<TestProps, "button">(() => <div />);

<Test as="a" href="/" />;
```

Using conditional type constraints

```ts
import React from "react";

type PropsWithAs<Props, As> = As extends React.ElementType
  ? Props & React.ComponentPropsWithoutRef<As> & { as?: As }
  : never;

type GetComponentRef<As> = As extends React.ElementType
  ? React.ComponentRef<As>
  : never;

type Render<Props, As> = (
  props: PropsWithAs<Props, As>,
  ref: React.ForwardedRef<GetComponentRef<As>>
) => React.ReactElement | null;

type Component<Props, DefaultAs> = <As = DefaultAs>(
  props: PropsWithAs<Props, As> & React.RefAttributes<GetComponentRef<As>>
) => React.ReactElement | null;

export const forwardRef = <Props, DefaultAs>(
  render: Render<Props, DefaultAs>
) => React.forwardRef(render) as Component<Props, DefaultAs>;

interface TestProps {
  variant?: "a" | "b" | "c";
}

const Test = forwardRef<TestProps, "button">(() => <div />);

<Test as="a" href="/" />;

```

### 🙁 Actual behavior

IntelliSense is slowed down using generic constraints, but using the same contraint on a conditional type does not.

### 🙂 Expected behavior

Using a constraint directly on generics or on a conditional type should have no difference in IntelliSense performance.