Skip to content
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

Improve constraints of conditional types applied to constrained type variables #56004

Merged
merged 9 commits into from
Nov 21, 2023

Conversation

ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Oct 6, 2023

With this PR we compute more accurate constraints for distributive conditional types applied to constrained type variables. For example:

type IsArray<T> = T extends any[] ? true : false;

function f1<U extends object>(x: IsArray<U>) {
    let t: true = x;   // Error
    let f: false = x;  // Error, but previously wasn't
}

Previously, we'd obtain the constraint of IsArray<U> by applying the distributive conditional type to the constraint of U, which resolves to false (because object doesn't extend any[]). But really, it ought to be boolean (i.e. true | false) since clearly something constrained to object both could or could not be an array.

A type variable represents any possible type within its constraint. So, given a type parameter T with the constraint C, the constraint of T extends X ? A : B is

  • A when C is known to always extend X,
  • B when C is known to never extend X, or
  • A | B when C possibly extends X.

We previously didn't consider the third possibility. With this PR, we choose the third outcome when C is not assignable to X, but X (or, if X is a union type, some constituent of X) is assignable to C.

Fixes #30152.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 6, 2023
@ahejlsberg
Copy link
Member Author

@typescript-bot test top100
@typescript-bot user test this
@typescript-bot run dt
@typescript-bot perf test this faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 6, 2023

Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at 2f5d9e9. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 6, 2023

Heya @ahejlsberg, I've started to run the diff-based user code test suite on this PR at 2f5d9e9. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 6, 2023

Heya @ahejlsberg, I've started to run the tsc-only perf test suite on this PR at 2f5d9e9. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 6, 2023

Heya @ahejlsberg, I've started to run the diff-based top-repos suite on this PR at 2f5d9e9. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@ahejlsberg
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v18.15.0, x64)
Memory used 295,077k (± 0.02%) 295,077k (± 0.01%) ~ 295,034k 295,133k p=0.689 n=6
Parse Time 2.63s (± 0.48%) 2.63s (± 0.64%) ~ 2.61s 2.65s p=1.000 n=6
Bind Time 0.84s (± 0.89%) 0.84s (± 1.06%) ~ 0.83s 0.85s p=0.798 n=6
Check Time 8.06s (± 0.20%) 8.07s (± 0.21%) ~ 8.04s 8.09s p=0.217 n=6
Emit Time 7.05s (± 0.66%) 7.05s (± 0.37%) ~ 7.02s 7.10s p=0.805 n=6
Total Time 18.58s (± 0.27%) 18.59s (± 0.21%) ~ 18.54s 18.65s p=0.629 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 190,688k (± 0.01%) 191,664k (± 1.24%) ~ 190,674k 196,504k p=0.378 n=6
Parse Time 1.35s (± 0.38%) 1.34s (± 0.61%) ~ 1.33s 1.35s p=0.523 n=6
Bind Time 0.73s (± 0.00%) 0.73s (± 0.00%) ~ 0.73s 0.73s p=1.000 n=6
Check Time 9.20s (± 0.73%) 9.20s (± 0.89%) ~ 9.15s 9.37s p=0.809 n=6
Emit Time 2.63s (± 0.52%) 2.60s (± 0.32%) -0.02s (- 0.82%) 2.60s 2.62s p=0.013 n=6
Total Time 13.90s (± 0.46%) 13.88s (± 0.58%) ~ 13.83s 14.04s p=0.463 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,295k (± 0.01%) 347,297k (± 0.01%) ~ 347,256k 347,322k p=0.810 n=6
Parse Time 2.46s (± 0.48%) 2.47s (± 0.30%) ~ 2.46s 2.48s p=0.150 n=6
Bind Time 0.94s (± 0.87%) 0.94s (± 0.00%) ~ 0.94s 0.94s p=0.405 n=6
Check Time 6.89s (± 0.30%) 6.93s (± 0.42%) +0.04s (+ 0.61%) 6.89s 6.97s p=0.023 n=6
Emit Time 4.03s (± 0.69%) 4.02s (± 0.44%) ~ 4.01s 4.05s p=1.000 n=6
Total Time 14.31s (± 0.20%) 14.36s (± 0.27%) ~ 14.30s 14.39s p=0.052 n=6
TFS - node (v18.15.0, x64)
Memory used 302,555k (± 0.01%) 302,545k (± 0.00%) ~ 302,535k 302,556k p=0.687 n=6
Parse Time 2.00s (± 0.58%) 2.00s (± 1.07%) ~ 1.97s 2.03s p=0.870 n=6
Bind Time 1.00s (± 1.04%) 1.00s (± 0.41%) ~ 1.00s 1.01s p=0.528 n=6
Check Time 6.25s (± 0.58%) 6.26s (± 0.31%) ~ 6.23s 6.28s p=0.568 n=6
Emit Time 3.57s (± 0.29%) 3.56s (± 0.60%) ~ 3.52s 3.58s p=0.616 n=6
Total Time 12.82s (± 0.23%) 12.81s (± 0.33%) ~ 12.74s 12.86s p=0.871 n=6
material-ui - node (v18.15.0, x64)
Memory used 470,530k (± 0.00%) 568,506k (± 0.01%) 🔻+97,977k (+20.82%) 568,446k 568,552k p=0.005 n=6
Parse Time 2.57s (± 0.72%) 2.58s (± 0.55%) ~ 2.56s 2.60s p=0.516 n=6
Bind Time 0.99s (± 0.99%) 0.99s (± 1.18%) ~ 0.97s 1.00s p=1.000 n=6
Check Time 16.61s (± 0.59%) 19.11s (± 0.66%) 🔻+2.50s (+15.03%) 18.94s 19.29s p=0.005 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.18s (± 0.40%) 22.68s (± 0.48%) 🔻+2.50s (+12.40%) 22.53s 22.83s p=0.005 n=6
xstate - node (v18.15.0, x64)
Memory used 512,583k (± 0.02%) 511,800k (± 0.02%) -784k (- 0.15%) 511,733k 511,963k p=0.005 n=6
Parse Time 3.27s (± 0.39%) 3.27s (± 0.32%) ~ 3.26s 3.29s p=0.868 n=6
Bind Time 1.55s (± 0.58%) 1.55s (± 0.53%) ~ 1.54s 1.56s p=0.550 n=6
Check Time 2.87s (± 0.19%) 2.83s (± 0.65%) -0.04s (- 1.28%) 2.81s 2.86s p=0.008 n=6
Emit Time 0.08s (± 0.00%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=1.000 n=6
Total Time 7.76s (± 0.15%) 7.72s (± 0.23%) -0.04s (- 0.54%) 7.70s 7.75s p=0.008 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the top-repos suite comparing main and refs/pull/56004/merge:

Something interesting changed - please have a look.

Details

backstage/backstage

7 of 13 projects failed to build with the old tsc and were ignored

packages/cli/templates/default-react-plugin-package/tsconfig.json

react-hook-form/react-hook-form

2 of 3 projects failed to build with the old tsc and were ignored

tsconfig.json

vuejs/core

1 of 3 projects failed to build with the old tsc and were ignored

tsconfig.build.json

tsconfig.json

@typescript-bot
Copy link
Collaborator

Hey @ahejlsberg, the results of running the DT tests are ready.
There were interesting changes:

Branch only errors:

Package: reflexbox
Error:

Error: Errors in typescript@local for external dependencies:
node_modules/@emotion/styled/types/base.d.ts(127,22): error TS2344: Type 'ForwardedProps' does not satisfy the constraint 'keyof PropsOf<C>'.
  Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof PropsOf<C>'.
    Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...>'.
      Type 'ForwardedProps' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...>'.
        Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...>'.
          Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
            Type 'ForwardedProps' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
              Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
                Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                  Type 'ForwardedProps' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                    Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                      Type 'keyof ComponentProps<C> & string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                        Type 'ForwardedProps' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                          Type 'keyof ComponentProps<C> & string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                            Type 'keyof ComponentProps<C> & string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined>'.
                              Type 'ForwardedProps' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined>'.
                                Type 'keyof ComponentProps<C> & string' is not assignable to type 'never'.
node_modules/@emotion/styled/types/base.d.ts(157,22): error TS2344: Type 'ForwardedProps' does not satisfy the constraint 'keyof PropsOf<C>'.
  Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof PropsOf<C>'.
    Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...> & keyof (C extends MemoExoticComponent<...> | LazyExoticComponent<...> ? ReactManagedAttributes<...> : ReactManagedAttributes<...>)'.
      Type 'ForwardedProps' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...> & keyof (C extends MemoExoticComponent<...> | LazyExoticComponent<...> ? ReactManagedAttributes<...> : ReactManagedAttributes<...>)'.
        Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...> & keyof (C extends MemoExoticComponent<...> | LazyExoticComponent<...> ? ReactManagedAttributes<...> : ReactManagedAttributes<...>)'.
          Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
            Type 'ForwardedProps' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
              Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
                Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                  Type 'ForwardedProps' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                    Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                      Type 'keyof ComponentProps<C> & string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                        Type 'ForwardedProps' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                          Type 'keyof ComponentProps<C> & string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                            Type 'keyof ComponentProps<C> & string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined>'.
                              Type 'ForwardedProps' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined>'.
                                Type 'keyof ComponentProps<C> & string' is not assignable to type 'never'.

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint/dist/index.js:151:9)

Package: knex-cleaner
Error:

Error: Errors in typescript@local for external dependencies:
node_modules/knex/types/index.d.ts(1240,50): error TS2344: Type 'ResolveTableType<TRecord, "base">' does not satisfy the constraint '{}'.
  Type 'unknown' is not assignable to type '{}'.
node_modules/knex/types/index.d.ts(1255,50): error TS2344: Type 'ResolveTableType<TRecord, "base">' does not satisfy the constraint '{}'.

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint/dist/index.js:151:9)

Package: mui-datatables
Error:

Error: Errors in typescript@local for external dependencies:
node_modules/@emotion/styled/types/base.d.ts(127,22): error TS2344: Type 'ForwardedProps' does not satisfy the constraint 'keyof PropsOf<C>'.
  Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof PropsOf<C>'.
    Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...>'.
      Type 'ForwardedProps' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...>'.
        Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...>'.
          Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
            Type 'ForwardedProps' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
              Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
                Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                  Type 'ForwardedProps' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                    Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                      Type 'keyof ComponentProps<C> & string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                        Type 'ForwardedProps' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                          Type 'keyof ComponentProps<C> & string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                            Type 'keyof ComponentProps<C> & string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined>'.
                              Type 'ForwardedProps' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined>'.
                                Type 'keyof ComponentProps<C> & string' is not assignable to type 'never'.
node_modules/@emotion/styled/types/base.d.ts(157,22): error TS2344: Type 'ForwardedProps' does not satisfy the constraint 'keyof PropsOf<C>'.
  Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof PropsOf<C>'.
    Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...> & keyof (C extends MemoExoticComponent<...> | LazyExoticComponent<...> ? ReactManagedAttributes<...> : ReactManagedAttributes<...>)'.
      Type 'ForwardedProps' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...> & keyof (C extends MemoExoticComponent<...> | LazyExoticComponent<...> ? ReactManagedAttributes<...> : ReactManagedAttributes<...>)'.
        Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...> & keyof (C extends MemoExoticComponent<...> | LazyExoticComponent<...> ? ReactManagedAttributes<...> : ReactManagedAttributes<...>)'.
          Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
            Type 'ForwardedProps' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
              Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
                Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                  Type 'ForwardedProps' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                    Type 'keyof ComponentProps<C> & string' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                      Type 'keyof ComponentProps<C> & string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                        Type 'ForwardedProps' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                          Type 'keyof ComponentProps<C> & string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                            Type 'keyof ComponentProps<C> & string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined>'.
                              Type 'ForwardedProps' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined>'.
                                Type 'keyof ComponentProps<C> & string' is not assignable to type 'never'.
node_modules/@mui/styled-engine/index.d.ts(160,22): error TS2344: Type 'ForwardedProps' does not satisfy the constraint 'keyof PropsOf<C>'.
  Type 'keyof ComponentProps<C>' is not assignable to type 'keyof PropsOf<C>'.
    Type 'string | number | symbol' is not assignable to type 'keyof PropsOf<C>'.
      Type 'string' is not assignable to type 'keyof PropsOf<C>'.
        Type 'string' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...>'.
          Type 'keyof ComponentProps<C>' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...>'.
            Type 'ForwardedProps' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...>'.
              Type 'keyof ComponentProps<C>' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...>'.
                Type 'string | number | symbol' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...>'.
                  Type 'string' is not assignable to type 'keyof ComponentProps<C> & keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>> & keyof Defaultize<...> & keyof Defaultize<...>'.
                    Type 'string' is not assignable to type 'keyof ComponentProps<C>'.
                      Type 'keyof ComponentProps<C>' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
                        Type 'ForwardedProps' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
                          Type 'keyof ComponentProps<C>' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
                            Type 'string | number | symbol' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
                              Type 'string' is not assignable to type 'keyof MergePropTypes<ComponentProps<C>, InferProps<WeakValidationMap<ComponentProps<C>> | undefined>>'.
                                Type 'string' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                                  Type 'keyof ComponentProps<C>' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                                    Type 'ForwardedProps' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                                      Type 'keyof ComponentProps<C>' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                                        Type 'string | number | symbol' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                                          Type 'string' is not assignable to type 'keyof (IsExactlyAny<ComponentProps<C>> extends true ? InferProps<WeakValidationMap<ComponentProps<C>> | undefined> : string extends keyof ComponentProps<...> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                                            Type 'string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                                              Type 'keyof ComponentProps<C>' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                                                Type 'ForwardedProps' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                                                  Type 'keyof ComponentProps<C>' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                                                    Type 'string | number | symbol' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                                                      Type 'string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined> & keyof (string extends keyof ComponentProps<C> ? ComponentProps<...> : Pick<...> & ... 1 more ... & Pick<...>)'.
                                                        Type 'string' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined>'.
                                                          Type 'keyof ComponentProps<C>' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined>'.
                                                            Type 'ForwardedProps' is not assignable to type 'RequiredKeys<WeakValidationMap<ComponentProps<C>> | undefined>'.
                                                              Type 'keyof ComponentProps<C>' is not assignable to type 'never'.
                                                                Type 'string | number | symbol' is not assignable to type 'never'.
                                                                  Type 'string' is not assignable to type 'never'.

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint/dist/index.js:151:9)

Package: knex-db-manager
Error:

Error: Errors in typescript@local for external dependencies:
node_modules/knex/types/index.d.ts(1091,50): error TS2344: Type 'ResolveTableType<TRecord, "base">' does not satisfy the constraint '{}'.
  Type 'unknown' is not assignable to type '{}'.
node_modules/knex/types/index.d.ts(1103,50): error TS2344: Type 'ResolveTableType<TRecord, "base">' does not satisfy the constraint '{}'.

    at testTypesVersion (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint/dist/index.js:194:15)
    at async runTests (/home/vsts/work/1/s/DefinitelyTyped-tools/packages/dtslint/dist/index.js:151:9)

You can check the log here.

@gabritto
Copy link
Member

gabritto commented Oct 6, 2023

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 6, 2023

Heya @gabritto, I've started to run the tarball bundle task on this PR at 2f5d9e9. You can monitor the build here.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 6, 2023

Hey @gabritto, I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/158126/artifacts?artifactName=tgz&fileId=C312C2036DEE5998F78828DF563EFC75917CF2508AF2CDEC50D916C993783F9502&fileName=/typescript-5.3.0-insiders.20231006.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

@ahejlsberg
Copy link
Member Author

@typescript-bot test top100
@typescript-bot user test this
@typescript-bot run dt
@typescript-bot perf test this faster

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 6, 2023

Heya @ahejlsberg, I've started to run the diff-based user code test suite on this PR at c7613d6. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 6, 2023

Heya @ahejlsberg, I've started to run the tsc-only perf test suite on this PR at c7613d6. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 6, 2023

Heya @ahejlsberg, I've started to run the parallelized Definitely Typed test suite on this PR at c7613d6. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

typescript-bot commented Oct 6, 2023

Heya @ahejlsberg, I've started to run the diff-based top-repos suite on this PR at c7613d6. You can monitor the build here.

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@ahejlsberg
The results of the perf run you requested are in!

Here they are:

Compiler

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Angular - node (v18.15.0, x64)
Memory used 295,069k (± 0.01%) 295,049k (± 0.02%) ~ 294,949k 295,095k p=0.378 n=6
Parse Time 2.64s (± 0.48%) 2.63s (± 0.40%) ~ 2.62s 2.65s p=0.456 n=6
Bind Time 0.84s (± 0.99%) 0.85s (± 0.96%) ~ 0.83s 0.85s p=0.673 n=6
Check Time 8.05s (± 0.54%) 8.06s (± 0.31%) ~ 8.02s 8.10s p=0.568 n=6
Emit Time 7.05s (± 0.56%) 7.05s (± 0.20%) ~ 7.03s 7.07s p=0.366 n=6
Total Time 18.59s (± 0.25%) 18.59s (± 0.19%) ~ 18.54s 18.65s p=0.936 n=6
Compiler-Unions - node (v18.15.0, x64)
Memory used 194,451k (± 1.26%) 191,117k (± 0.54%) ~ 190,663k 193,214k p=0.065 n=6
Parse Time 1.34s (± 0.61%) 1.34s (± 1.31%) ~ 1.31s 1.35s p=0.730 n=6
Bind Time 0.73s (± 0.00%) 0.73s (± 0.00%) ~ 0.73s 0.73s p=1.000 n=6
Check Time 9.21s (± 1.04%) 9.21s (± 0.75%) ~ 9.13s 9.32s p=1.000 n=6
Emit Time 2.63s (± 0.81%) 2.60s (± 0.63%) ~ 2.59s 2.63s p=0.061 n=6
Total Time 13.91s (± 0.79%) 13.88s (± 0.50%) ~ 13.82s 14.01s p=0.573 n=6
Monaco - node (v18.15.0, x64)
Memory used 347,311k (± 0.01%) 347,286k (± 0.01%) ~ 347,265k 347,312k p=0.093 n=6
Parse Time 2.46s (± 0.33%) 2.46s (± 0.42%) ~ 2.44s 2.47s p=0.932 n=6
Bind Time 0.94s (± 0.43%) 0.94s (± 0.67%) ~ 0.93s 0.95s p=0.673 n=6
Check Time 6.94s (± 0.51%) 6.90s (± 0.42%) ~ 6.87s 6.94s p=0.089 n=6
Emit Time 4.03s (± 0.41%) 4.03s (± 0.26%) ~ 4.01s 4.04s p=1.000 n=6
Total Time 14.37s (± 0.25%) 14.33s (± 0.16%) ~ 14.30s 14.36s p=0.075 n=6
TFS - node (v18.15.0, x64)
Memory used 302,551k (± 0.00%) 302,542k (± 0.00%) ~ 302,524k 302,561k p=0.336 n=6
Parse Time 1.99s (± 1.00%) 2.00s (± 1.08%) ~ 1.98s 2.03s p=0.328 n=6
Bind Time 1.00s (± 1.03%) 1.00s (± 0.75%) ~ 0.99s 1.01s p=0.931 n=6
Check Time 6.24s (± 0.29%) 6.24s (± 0.34%) ~ 6.21s 6.26s p=0.935 n=6
Emit Time 3.57s (± 0.34%) 3.57s (± 0.41%) ~ 3.55s 3.59s p=0.564 n=6
Total Time 12.80s (± 0.29%) 12.82s (± 0.24%) ~ 12.78s 12.86s p=0.571 n=6
material-ui - node (v18.15.0, x64)
Memory used 470,502k (± 0.00%) 470,551k (± 0.00%) +49k (+ 0.01%) 470,528k 470,580k p=0.005 n=6
Parse Time 2.57s (± 0.16%) 2.58s (± 0.68%) ~ 2.55s 2.60s p=0.246 n=6
Bind Time 1.00s (± 0.63%) 0.99s (± 0.52%) ~ 0.99s 1.00s p=0.091 n=6
Check Time 16.60s (± 0.47%) 16.73s (± 0.20%) +0.13s (+ 0.76%) 16.70s 16.78s p=0.016 n=6
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) ~ 0.00s 0.00s p=1.000 n=6
Total Time 20.17s (± 0.36%) 20.30s (± 0.20%) +0.13s (+ 0.64%) 20.24s 20.36s p=0.010 n=6
xstate - node (v18.15.0, x64)
Memory used 512,602k (± 0.02%) 511,778k (± 0.01%) -824k (- 0.16%) 511,714k 511,836k p=0.005 n=6
Parse Time 3.27s (± 0.42%) 3.28s (± 0.25%) ~ 3.27s 3.29s p=0.183 n=6
Bind Time 1.55s (± 0.53%) 1.55s (± 0.26%) ~ 1.54s 1.55s p=0.206 n=6
Check Time 2.86s (± 1.05%) 2.81s (± 0.61%) -0.05s (- 1.92%) 2.78s 2.83s p=0.005 n=6
Emit Time 0.08s (± 7.90%) 0.08s (± 0.00%) ~ 0.08s 0.08s p=1.000 n=6
Total Time 7.76s (± 0.52%) 7.70s (± 0.18%) -0.05s (- 0.71%) 7.69s 7.73s p=0.009 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Angular - node (v18.15.0, x64)
  • Compiler-Unions - node (v18.15.0, x64)
  • Monaco - node (v18.15.0, x64)
  • TFS - node (v18.15.0, x64)
  • material-ui - node (v18.15.0, x64)
  • xstate - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@ahejlsberg Here are the results of running the user test suite comparing main and refs/pull/56004/merge:

There were infrastructure failures potentially unrelated to your change:

  • 3 instances of "Package install failed"
  • 1 instance of "Unknown failure"

Otherwise...

Everything looks good!

@ahejlsberg
Copy link
Member Author

Latest commit changes checking for the "possibly extends" case to use a reverse assignability check. This check is not quite as permissible as a comparability check, meaning we'll less often hit the "possibly extends" case where the constraint is a union. Still, since constraint types are typically close-to-top types (like object or {}), it isn't likely to matter. And, certainly, performance with the reverse assignability test is much more acceptable.

@ahejlsberg ahejlsberg added this to the TypeScript 5.4.0 milestone Oct 6, 2023
@voxpelli
Copy link

As an FYI in case anyone follows this issue, it turned out that this caused a regression in type-fest and I'm still debugging why and/or how to fix, but want to mention here in the meanwhile, might file an issue later: sindresorhus/type-fest#784

voxpelli added a commit to sindresorhus/type-fest that referenced this pull request Jan 29, 2024
After the change in microsoft/TypeScript#56004 the `PickRestType` was causing some types to be considered theoretically infinite in their recursion.

I can't wrap my mind around exactly why right now, but I can see how `PickRestType` on a crazy long tuple will cause a very deep recursion, so I decided to simply cap its recursion and return `unknown[]` if it goes past that point and that solved the errors.

Side effects:

- In practice: rarely any I believe
- In theory: some merged types will regress to `unknown[]` in TypeScript versions older than 5.4

Considerations:

Is the `DepthTracker extends Array<true> = []` + `PickRestTypeMaxDepth extends DepthTracker['length']` a good way to track depth? I know I have done a depth check previous times but can't remember what solution I picked then.

Fixes #784
@acutmore acutmore mentioned this pull request Feb 21, 2024
1 task
Haroenv added a commit to algolia/instantsearch that referenced this pull request Jun 20, 2024
I can't manage to reproduce this locally, even if i update everything to 5.4.5, but in a fresh Next.js example (like  https://codesandbox.io/s/47fy7c) `hitsPerPage` isn't accepted to Configure (because PlainSearchParameters is any)

This is I believe linked to microsoft/TypeScript#56004, maybe also to sindresorhus/type-fest#846 (although the case seems different).

Essentially before this change the types like `ClientLiteV5` were evaluated to `any` instead of `unknown`, poisoning the entire type and turning everything into any.

The solution is to first check if `typeof AlgoliaSearchLite` is any, and if it is any we don't even evaluate the rest of teh type. Of course if it isn't any it works correctly for v5 still.

Again, unfortunately this isn't reproducible in this repo, even when every typescript version is updated to 5.4.5, but at least the error will be fixed

fixes #5989
Haroenv added a commit to algolia/instantsearch that referenced this pull request Jun 20, 2024
)

I can't manage to reproduce this locally, even if i update everything to 5.4.5, but in a fresh Next.js example (like  https://codesandbox.io/s/47fy7c) `hitsPerPage` isn't accepted to Configure (because PlainSearchParameters is any)

This is I believe linked to microsoft/TypeScript#56004, maybe also to sindresorhus/type-fest#846 (although the case seems different).

Essentially before this change the types like `ClientLiteV5` were evaluated to `any` instead of `unknown`, poisoning the entire type and turning everything into any.

The solution is to first check if `typeof AlgoliaSearchLite` is any, and if it is any we don't even evaluate the rest of teh type. Of course if it isn't any it works correctly for v5 still.

Again, unfortunately this isn't reproducible in this repo, even when every typescript version is updated to 5.4.5, but at least the error will be fixed

fixes #5989
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Conditional types are incorrectly narrowed
6 participants