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

[WIP] Support condition always true in prefix unary expression #60068

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

tjenkinson
Copy link
Contributor

Opening as draft for now so we can run the extended tests and see how much breakage there is. See #46140 (comment)

cc @gabritto

Fixes #46140

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Sep 26, 2024
@tjenkinson tjenkinson changed the title Support condition always true in prefix unary expression [WIP] Support condition always true in prefix unary expression Sep 26, 2024
@gabritto
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 26, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started 👀 Results
user test this ✅ Started 👀 Results
run dt ✅ Started 👀 Results
perf test this faster ✅ Started 👀 Results

@typescript-bot
Copy link
Collaborator

Hey @gabritto, the results of running the DT tests are ready.

There were interesting changes:

Branch only errors:

Package: js-fixtures
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/js-fixtures/js-fixtures-tests.ts
  16:10  error  TypeScript@local compile error: 
This condition will always return true since this function is always defined. Did you mean to call it instead?  @definitelytyped/expect

✖ 1 problem (1 error, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.23_typescript@5.7.0-dev.20240926/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.23_typescript@5.7.0-dev.20240926/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

Package: xdate
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/xdate/xdate-tests.ts
  1177:18  error  TypeScript@local compile error: 
This condition will always return true since this function is always defined. Did you mean to call it instead?  @definitelytyped/expect

✖ 1 problem (1 error, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.23_typescript@5.7.0-dev.20240926/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.23_typescript@5.7.0-dev.20240926/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

Package: activex-excel
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/activex-excel/activex-excel-tests.ts
  98:10  error  TypeScript@local compile error: 
This condition will always return true since this function is always defined. Did you mean to call it instead?  @definitelytyped/expect

✖ 1 problem (1 error, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.23_typescript@5.7.0-dev.20240926/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.23_typescript@5.7.0-dev.20240926/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

Package: morgan
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/morgan/morgan-tests.ts
  88:10  error  TypeScript@local compile error: 
This condition will always return true since this function is always defined. Did you mean to call it instead?  @definitelytyped/expect

✖ 1 problem (1 error, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.23_typescript@5.7.0-dev.20240926/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.23_typescript@5.7.0-dev.20240926/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

Package: yandex-maps
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/yandex-maps/yandex-maps-tests.ts
  162:10  error  TypeScript@local compile error: 
This condition will always return true since this function is always defined. Did you mean to call it instead?  @definitelytyped/expect

✖ 1 problem (1 error, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.23_typescript@5.7.0-dev.20240926/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.23_typescript@5.7.0-dev.20240926/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

Package: bluebird
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/bluebird/bluebird-tests.ts
  827:11  error  TypeScript@local compile error: 
This condition will always return true since this 'import("/mnt/vss/_work/1/DefinitelyTyped/types/bluebird/index")<Foo>' is always defined  @definitelytyped/expect
  848:11  error  TypeScript@local compile error: 
This condition will always return true since this 'import("/mnt/vss/_work/1/DefinitelyTyped/types/bluebird/index")<Foo>' is always defined  @definitelytyped/expect

✖ 2 problems (2 errors, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.23_typescript@5.7.0-dev.20240926/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.23_typescript@5.7.0-dev.20240926/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

You can check the log here.

@typescript-bot
Copy link
Collaborator

@gabritto Here are the results of running the user tests with tsc comparing main and refs/pull/60068/merge:

Something interesting changed - please have a look.

Details

lodash

/mnt/ts_downloads/_/m/lodash/tsconfig.json

  • [NEW] error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
    • /mnt/ts_downloads/_/m/lodash/node_modules/lodash/_getSymbols.js(20,19)
    • /mnt/ts_downloads/_/m/lodash/node_modules/lodash/_getSymbolsIn.js(16,21)

pyright

/mnt/ts_downloads/_/m/pyright/build.sh

  • [NEW] error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
    • /mnt/ts_downloads/_/m/pyright/pyright: ../pyright-internal/src/common/memUtils.ts(39,10)
    • /mnt/ts_downloads/_/m/pyright/pyright-internal: src/common/memUtils.ts(39,10)
    • /mnt/ts_downloads/_/m/pyright/vscode-pyright: ../pyright-internal/src/common/memUtils.ts(39,10)

webpack

tsconfig.types.json

xterm.js

src/tsconfig-library-base.json

@typescript-bot
Copy link
Collaborator

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

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 30 30 ~ ~ ~ p=1.000 n=6
Symbols 62,340 62,340 ~ ~ ~ p=1.000 n=6
Types 50,378 50,378 ~ ~ ~ p=1.000 n=6
Memory used 193,305k (± 0.75%) 193,310k (± 0.75%) ~ 192,690k 196,283k p=1.000 n=6
Parse Time 1.31s (± 0.64%) 1.30s (± 0.94%) ~ 1.29s 1.32s p=0.928 n=6
Bind Time 0.71s 0.71s ~ ~ ~ p=1.000 n=6
Check Time 9.54s (± 0.14%) 9.54s (± 0.39%) ~ 9.49s 9.58s p=0.683 n=6
Emit Time 2.71s (± 0.38%) 2.69s (± 1.96%) ~ 2.62s 2.76s p=0.213 n=6
Total Time 14.27s (± 0.15%) 14.25s (± 0.40%) ~ 14.20s 14.36s p=0.092 n=6
angular-1 - node (v18.15.0, x64)
Errors 7 18 🔻+11 (+157.14%) ~ ~ p=0.001 n=6
Symbols 947,102 947,114 +12 (+ 0.00%) ~ ~ p=0.001 n=6
Types 410,738 410,747 +9 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 1,224,036k (± 0.01%) 1,223,972k (± 0.01%) ~ 1,223,891k 1,224,044k p=0.128 n=6
Parse Time 6.60s (± 0.43%) 6.64s (± 0.91%) ~ 6.55s 6.73s p=0.227 n=6
Bind Time 1.86s (± 0.59%) 1.87s (± 0.40%) ~ 1.86s 1.88s p=0.062 n=6
Check Time 31.28s (± 0.49%) 31.39s (± 0.35%) ~ 31.24s 31.54s p=0.199 n=6
Emit Time 15.07s (± 0.64%) 15.02s (± 0.18%) ~ 14.98s 15.05s p=0.226 n=6
Total Time 54.81s (± 0.44%) 54.91s (± 0.23%) ~ 54.75s 55.05s p=0.378 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,521,651 2,521,651 ~ ~ ~ p=1.000 n=6
Types 936,037 936,038 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,351,721k (± 0.00%) 2,351,798k (± 0.00%) +78k (+ 0.00%) 2,351,728k 2,351,860k p=0.031 n=6
Parse Time 9.28s (± 0.23%) 9.28s (± 0.28%) ~ 9.25s 9.31s p=0.684 n=6
Bind Time 2.13s (± 0.48%) 2.13s (± 0.35%) ~ 2.12s 2.14s p=0.931 n=6
Check Time 73.53s (± 0.53%) 73.43s (± 0.54%) ~ 72.96s 74.02s p=0.575 n=6
Emit Time 0.27s (± 2.98%) 0.28s (± 1.47%) ~ 0.27s 0.28s p=0.248 n=6
Total Time 85.22s (± 0.43%) 85.12s (± 0.46%) ~ 84.64s 85.65s p=0.689 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 12 🔻+12 (+ ∞%) ~ ~ p=0.001 n=6
Symbols 1,250,125 1,433,231 🔻+183,106 (+14.65%) ~ ~ p=0.001 n=6
Types 264,990 265,160 +170 (+ 0.06%) ~ ~ p=0.001 n=6
Memory used 2,404,629k (± 0.02%) 2,998,491k (± 0.01%) 🔻+593,863k (+24.70%) 2,998,083k 2,999,047k p=0.005 n=6
Parse Time 5.15s (± 0.86%) 8.61s (± 0.55%) 🔻+3.46s (+67.25%) 8.52s 8.65s p=0.005 n=6
Bind Time 1.90s (± 0.61%) 3.19s (± 0.58%) 🔻+1.29s (+67.92%) 3.18s 3.23s p=0.005 n=6
Check Time 34.89s (± 0.28%) 34.75s (± 0.67%) ~ 34.42s 35.13s p=0.108 n=6
Emit Time 3.02s (± 0.80%) 2.98s (± 1.57%) ~ 2.93s 3.04s p=0.336 n=6
Total Time 44.96s (± 0.26%) 49.55s (± 0.54%) 🔻+4.59s (+10.20%) 49.19s 49.96s p=0.005 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 12 🔻+12 (+ ∞%) ~ ~ p=0.001 n=6
Symbols 1,250,125 1,433,231 🔻+183,106 (+14.65%) ~ ~ p=0.001 n=6
Types 264,990 265,160 +170 (+ 0.06%) ~ ~ p=0.001 n=6
Memory used 2,479,585k (± 0.02%) 3,078,730k (± 0.01%) 🔻+599,145k (+24.16%) 3,078,141k 3,079,257k p=0.005 n=6
Parse Time 6.32s (± 0.67%) 10.59s (± 0.77%) 🔻+4.26s (+67.45%) 10.50s 10.73s p=0.005 n=6
Bind Time 2.04s (± 0.40%) 3.61s (± 0.33%) 🔻+1.58s (+77.41%) 3.60s 3.63s p=0.005 n=6
Check Time 41.67s (± 0.89%) 41.56s (± 0.45%) ~ 41.28s 41.73s p=0.689 n=6
Emit Time 3.66s (± 3.76%) 3.60s (± 2.34%) ~ 3.49s 3.73s p=0.518 n=6
Total Time 53.73s (± 0.41%) 59.37s (± 0.23%) 🔻+5.64s (+10.50%) 59.15s 59.50s p=0.005 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 4 🔻+4 (+ ∞%) ~ ~ p=0.001 n=6
Symbols 260,972 260,974 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 106,405 106,405 ~ ~ ~ p=1.000 n=6
Memory used 436,765k (± 0.03%) 436,903k (± 0.04%) ~ 436,670k 437,163k p=0.128 n=6
Parse Time 3.44s (± 0.91%) 3.43s (± 0.63%) ~ 3.42s 3.47s p=0.462 n=6
Bind Time 1.30s (± 0.49%) 1.30s (± 0.31%) ~ 1.30s 1.31s p=0.673 n=6
Check Time 18.22s (± 0.54%) 18.18s (± 0.28%) ~ 18.12s 18.23s p=0.872 n=6
Emit Time 1.52s (± 1.13%) 1.52s (± 1.88%) ~ 1.49s 1.55s p=1.000 n=6
Total Time 24.48s (± 0.44%) 24.44s (± 0.28%) ~ 24.35s 24.52s p=0.630 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 68 75 🔻+7 (+10.29%) ~ ~ p=0.001 n=6
Symbols 225,916 225,916 ~ ~ ~ p=1.000 n=6
Types 94,414 94,417 +3 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 370,943k (± 0.02%) 370,885k (± 0.01%) ~ 370,832k 370,940k p=0.093 n=6
Parse Time 3.45s (± 0.89%) 3.46s (± 0.94%) ~ 3.43s 3.50s p=0.462 n=6
Bind Time 1.93s (± 1.11%) 1.93s (± 1.48%) ~ 1.89s 1.96s p=0.871 n=6
Check Time 19.51s (± 0.50%) 19.61s (± 0.52%) ~ 19.51s 19.77s p=0.109 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.89s (± 0.50%) 25.00s (± 0.40%) ~ 24.90s 25.15s p=0.173 n=6
vscode - node (v18.15.0, x64)
Errors 1 16 🔻+15 (+1,500.00%) ~ ~ p=0.001 n=6
Symbols 3,104,470 3,104,541 +71 (+ 0.00%) ~ ~ p=0.001 n=6
Types 1,070,027 1,070,068 +41 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 3,199,724k (± 0.00%) 3,199,708k (± 0.01%) ~ 3,198,988k 3,199,959k p=0.298 n=6
Parse Time 13.94s (± 0.12%) 13.98s (± 0.33%) ~ 13.92s 14.06s p=0.053 n=6
Bind Time 4.45s (± 2.20%) 4.44s (± 2.77%) ~ 4.34s 4.60s p=0.872 n=6
Check Time 82.47s (± 0.28%) 82.89s (± 0.31%) +0.41s (+ 0.50%) 82.62s 83.25s p=0.020 n=6
Emit Time 22.41s (± 0.63%) 23.18s (± 5.23%) ~ 22.31s 25.10s p=0.687 n=6
Total Time 123.26s (± 0.24%) 124.48s (± 0.92%) +1.22s (+ 0.99%) 123.28s 126.04s p=0.020 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 278,997 278,997 ~ ~ ~ p=1.000 n=6
Types 113,861 113,861 ~ ~ ~ p=1.000 n=6
Memory used 428,555k (± 0.03%) 428,626k (± 0.03%) ~ 428,445k 428,729k p=0.298 n=6
Parse Time 4.91s (± 0.44%) 4.88s (± 0.69%) ~ 4.84s 4.93s p=0.260 n=6
Bind Time 2.12s (± 0.97%) 2.13s (± 1.22%) ~ 2.09s 2.17s p=0.465 n=6
Check Time 21.94s (± 0.54%) 21.91s (± 0.34%) ~ 21.84s 22.04s p=0.689 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 28.97s (± 0.38%) 28.93s (± 0.27%) ~ 28.82s 29.02s p=0.748 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 1 🔻+1 (+ ∞%) ~ ~ p=0.001 n=6
Symbols 540,027 540,027 ~ ~ ~ p=1.000 n=6
Types 181,292 181,292 ~ ~ ~ p=1.000 n=6
Memory used 483,616k (± 0.01%) 483,642k (± 0.01%) ~ 483,583k 483,711k p=0.575 n=6
Parse Time 4.00s (± 0.41%) 4.01s (± 0.26%) ~ 4.00s 4.03s p=0.288 n=6
Bind Time 1.43s (± 0.72%) 1.44s (± 0.57%) ~ 1.43s 1.45s p=0.121 n=6
Check Time 22.90s (± 0.35%) 22.89s (± 0.21%) ~ 22.81s 22.95s p=0.748 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 28.33s (± 0.28%) 28.34s (± 0.17%) ~ 28.27s 28.41s p=0.747 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@gabritto Here are the results of running the top 400 repos with tsc comparing main and refs/pull/60068/merge:

Something interesting changed - please have a look.

Details

adobe/react-spectrum

9 of 15 projects failed to build with the old tsc and were ignored

packages/dev/codemods/tsconfig.json

apollographql/apollo-client

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

tsconfig.json

baidu/amis

4 of 5 projects failed to build with the old tsc and were ignored

packages/amis-formula/tsconfig-for-declaration.json

blakeblackshear/frigate

web/tsconfig.json

cheeriojs/cheerio

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

tsconfig.typedoc.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

date-fns/date-fns

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

tsconfig.lib.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

tsconfig.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

desktop/desktop

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

tsconfig.json

ether/etherpad-lite

src/tsconfig.json

FuelLabs/fuels-ts

34 of 58 projects failed to build with the old tsc and were ignored

packages/crypto/tsconfig.dts.json

gitpod-io/gitpod

12 of 20 projects failed to build with the old tsc and were ignored

components/gitpod-db/tsconfig.json

google/blockly

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

tsconfig.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

immich-app/immich

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

server/tsconfig.build.json

jupyterlab/jupyterlab

46 of 59 projects failed to build with the old tsc and were ignored

examples/filebrowser/src/tsconfig.json

konvajs/konva

tsconfig.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

microsoft/vscode

4 of 53 projects failed to build with the old tsc and were ignored

src/tsconfig.tsec.json

src/tsconfig.monaco.json

src/tsconfig.json

extensions/html-language-features/server/tsconfig.json

extensions/gulp/tsconfig.json

extensions/emmet/tsconfig.json

extensions/css-language-features/server/tsconfig.json

  • error TS2801: This condition will always return true since this 'Thenable<import("/mnt/ts_downloads/_/m/vscode/extensions/css-language-features/server/node_modules/vscode-css-languageservice/lib/umd/cssLanguageTypes").LanguageSettings | undefined>' is always defined.

openai-translator/openai-translator

tsconfig.json

reduxjs/react-redux

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

tsconfig.json

tsconfig.build.json

reduxjs/redux-devtools

25 of 58 projects failed to build with the old tsc and were ignored

packages/d3-state-visualizer/tsconfig.json

extension/tsconfig.json

signalapp/Signal-Desktop

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

sticker-creator/tsconfig.json

tinacms/tinacms

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

packages/@tinacms/mdx/tsconfig.json

tusen-ai/naive-ui

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

src/tsconfig.demo.json

vercel/swr

6 of 8 projects failed to build with the old tsc and were ignored

tsconfig.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

video-dev/hls.js

tsconfig.json

@gabritto
Copy link
Member

As I suspected, there are a lot of new errors in our extended tests.

I looked at a few of the new errors for uncalled functions, and there it seems that indeed, to support erroring on negated function conditions, we'd have to do the analysis of whether the function is called outside the if block, similar to what we do currently for non-negated function conditions to avoid false errors. I still have to look at the rest of the new function errors.

For the new promise errors, apollographql/apollo-client error looks like an error that is caused by an incorrect non-null assertion, so the new error is fine and could be fixed by them getting rid of the non-null assertion. For the blakeblackshear/frigate error, it looks like a bad new error because the promise is awaited and possibly we'd have to do a similar analysis of "is this promise awaited afterwards?". In vscode, https://github.com/microsoft/vscode/blob/f71675cbd9ba6aef444321cbe5faf8dd81340e3b/src/vs/base/node/id.ts#L82, https://github.com/microsoft/vscode/blob/f71675cbd9ba6aef444321cbe5faf8dd81340e3b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts#L526, https://github.com/microsoft/vscode/blob/f71675cbd9ba6aef444321cbe5faf8dd81340e3b/src/vs/workbench/services/search/common/search.ts#L819, https://github.com/microsoft/vscode/blob/f71675cbd9ba6aef444321cbe5faf8dd81340e3b/extensions/html-language-features/server/src/htmlServer.ts#L121, https://github.com/microsoft/vscode/blob/f71675cbd9ba6aef444321cbe5faf8dd81340e3b/extensions/emmet/src/test/abbreviationAction.test.ts#L223 are false errors, https://github.com/microsoft/vscode/blob/f71675cbd9ba6aef444321cbe5faf8dd81340e3b/src/vs/workbench/browser/layout.ts#L1759 is maybe a good error, https://github.com/microsoft/vscode/blob/f71675cbd9ba6aef444321cbe5faf8dd81340e3b/extensions/gulp/src/main.ts#L184 is a good error.
https://github.com/video-dev/hls.js/blob/5cfbc0a0ce5587fa2a49b607d1e95861b20ac5cb/tests/unit/controller/eme-controller.ts#L228 I don't even know how to interpret, and https://github.com/video-dev/hls.js/blob/5cfbc0a0ce5587fa2a49b607d1e95861b20ac5cb/tests/unit/controller/eme-controller.ts#L447 is a false error that I'm not even sure how we could avoid...

For desktop/desktop, gitpod-io/gitpod, the new errors are good and I think they all indicate bugs.

@gabritto
Copy link
Member

@tjenkinson I think both the function and promise cases will require some extra work for avoiding most of the false errors. Let me know if you'd still like to keep working on it, I think it's a very good feature since we had at least 3 bugs detected in the extended tests.

@tjenkinson
Copy link
Contributor Author

tjenkinson commented Sep 27, 2024

hey @gabritto thanks for looking through them super promising it found some actual issues.

Do you think we'll need to handle cases like this one where the usage happens later and is not part of the if/else block? Or would just checking the if/else block be good enough?

Happy to continue digging but I think that will be a bit more complex looking at how things are structured at the moment as block can't just be the if/else body. It would need to traverse up to the containing block, find the if/else, and then look in all items below it?

@tjenkinson
Copy link
Contributor Author

Actually maybe this is a different kind of check.

If there's an if (!a), it needs to be ignored if:

  1. inside the if block something is assigned to a
  2. there's an else that uses a

I'm not sure if (2) will happen much in the wild so maybe the 1st will be enough

@tjenkinson
Copy link
Contributor Author

Also not sure https://github.com/microsoft/vscode/blob/f71675cbd9ba6aef444321cbe5faf8dd81340e3b/extensions/emmet/src/test/abbreviationAction.test.ts#L223 is a false error? Looking at the types expandPromise should always be defined so that check looks redundant?

@gabritto
Copy link
Member

gabritto commented Oct 4, 2024

Also not sure https://github.com/microsoft/vscode/blob/f71675cbd9ba6aef444321cbe5faf8dd81340e3b/extensions/emmet/src/test/abbreviationAction.test.ts#L223 is a false error? Looking at the types expandPromise should always be defined so that check looks redundant?

I think you are right in this case. However, I think we should still support that case to avoid false errors in code written in a similar way.

@tjenkinson tjenkinson force-pushed the support-condition-always-true-in-prefix-unary-expression branch 5 times, most recently from d2604e2 to 8715473 Compare December 29, 2024 22:02
@tjenkinson tjenkinson force-pushed the support-condition-always-true-in-prefix-unary-expression branch from 4e7fe97 to 8f8b45c Compare December 30, 2024 22:00

function next() {
let task = tasks[index]
if (!task) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like might also have to bail if the source is accessing something from an array 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case looks like a bug in your PR code: we should not be erroring because task is used inside the else block.

@tjenkinson
Copy link
Contributor Author

Hey @gabritto I've pushed some changes so that now it should only apply if there's a single ! (given that !! appears to be a way to opt out of the behaviour for the positive case), and nothing is assigned to the variable inside if the if block.

Still need to add tests, but would be great if you could run the run the extended tests again and we could see if this reduces the false positives?

Also might need to add some logic to bail if it's accessing an item from an array

@gabritto
Copy link
Member

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Dec 30, 2024

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
test top400 ✅ Started 👀 Results
user test this ✅ Started 👀 Results
run dt ✅ Started 👀 Results
perf test this faster ✅ Started 👀 Results

instead of just `if (!object.fnOrPromise)`
@typescript-bot
Copy link
Collaborator

@gabritto Here are the results of running the user tests with tsc comparing main and refs/pull/60068/merge:

Something interesting changed - please have a look.

Details

lodash

/mnt/ts_downloads/_/m/lodash/tsconfig.json

  • [NEW] error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
    • /mnt/ts_downloads/_/m/lodash/node_modules/lodash/_getSymbols.js(20,19)
    • /mnt/ts_downloads/_/m/lodash/node_modules/lodash/_getSymbolsIn.js(16,21)

pyright

/mnt/ts_downloads/_/m/pyright/build.sh

  • [NEW] error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?
    • /mnt/ts_downloads/_/m/pyright/pyright: ../pyright-internal/src/common/memUtils.ts(42,10)
    • /mnt/ts_downloads/_/m/pyright/pyright-internal: src/common/memUtils.ts(42,10)
    • /mnt/ts_downloads/_/m/pyright/vscode-pyright: ../pyright-internal/src/common/memUtils.ts(42,10)

webpack

tsconfig.types.json

@typescript-bot
Copy link
Collaborator

Hey @gabritto, the results of running the DT tests are ready.

There were interesting changes:

Branch only errors:

Package: morgan
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/morgan/morgan-tests.ts
  88:10  error  TypeScript@local compile error: 
This condition will always return true since this function is always defined. Did you mean to call it instead?  @definitelytyped/expect

✖ 1 problem (1 error, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.28_typescript@5.8.0-dev.20241230/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.28_typescript@5.8.0-dev.20241230/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

Package: activex-excel
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/activex-excel/activex-excel-tests.ts
  98:10  error  TypeScript@local compile error: 
This condition will always return true since this function is always defined. Did you mean to call it instead?  @definitelytyped/expect

✖ 1 problem (1 error, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.28_typescript@5.8.0-dev.20241230/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.28_typescript@5.8.0-dev.20241230/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

Package: activex-shell
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/activex-shell/activex-shell-tests.ts
  426:6  error  TypeScript@local compile error: 
This condition will always return true since this function is always defined. Did you mean to call it instead?  @definitelytyped/expect

✖ 1 problem (1 error, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.28_typescript@5.8.0-dev.20241230/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.28_typescript@5.8.0-dev.20241230/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

Package: xdate
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/xdate/xdate-tests.ts
  1177:18  error  TypeScript@local compile error: 
This condition will always return true since this function is always defined. Did you mean to call it instead?  @definitelytyped/expect

✖ 1 problem (1 error, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.28_typescript@5.8.0-dev.20241230/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.28_typescript@5.8.0-dev.20241230/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

Package: js-fixtures
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/js-fixtures/js-fixtures-tests.ts
  16:10  error  TypeScript@local compile error: 
This condition will always return true since this function is always defined. Did you mean to call it instead?  @definitelytyped/expect

✖ 1 problem (1 error, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.28_typescript@5.8.0-dev.20241230/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.28_typescript@5.8.0-dev.20241230/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

Package: yandex-maps
Error:

Error: 
/mnt/vss/_work/1/DefinitelyTyped/types/yandex-maps/yandex-maps-tests.ts
  162:10  error  TypeScript@local compile error: 
This condition will always return true since this function is always defined. Did you mean to call it instead?  @definitelytyped/expect

✖ 1 problem (1 error, 0 warnings)

    at combineErrorsAndWarnings (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.28_typescript@5.8.0-dev.20241230/node_modules/@definitelytyped/dtslint/dist/index.js:194:28)
    at runTests (/mnt/vss/_work/1/DefinitelyTyped/node_modules/.pnpm/@definitelytyped+dtslint@0.2.28_typescript@5.8.0-dev.20241230/node_modules/@definitelytyped/dtslint/dist/index.js:186:20)

You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - node (v18.15.0, x64)
Errors 34 34 ~ ~ ~ p=1.000 n=6
Symbols 62,363 62,363 ~ ~ ~ p=1.000 n=6
Types 50,395 50,395 ~ ~ ~ p=1.000 n=6
Memory used 194,902k (± 1.05%) 193,724k (± 0.80%) ~ 193,003k 196,878k p=0.471 n=6
Parse Time 1.30s (± 0.80%) 1.30s (± 0.64%) ~ 1.29s 1.31s p=1.000 n=6
Bind Time 0.72s (± 0.57%) 0.72s ~ ~ ~ p=0.405 n=6
Check Time 9.75s (± 0.48%) 9.77s (± 0.36%) ~ 9.73s 9.83s p=0.518 n=6
Emit Time 2.71s (± 1.35%) 2.72s (± 0.98%) ~ 2.68s 2.76s p=0.462 n=6
Total Time 14.48s (± 0.54%) 14.51s (± 0.34%) ~ 14.44s 14.57s p=0.936 n=6
angular-1 - node (v18.15.0, x64)
Errors 37 47 🔻+10 (+27.03%) ~ ~ p=0.001 n=6
Symbols 947,936 947,948 +12 (+ 0.00%) ~ ~ p=0.001 n=6
Types 410,955 410,964 +9 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 1,225,775k (± 0.00%) 1,225,809k (± 0.00%) ~ 1,225,735k 1,225,903k p=0.378 n=6
Parse Time 6.67s (± 0.58%) 6.67s (± 0.59%) ~ 6.61s 6.71s p=0.872 n=6
Bind Time 1.88s (± 0.29%) 1.89s (± 0.27%) ~ 1.88s 1.89s p=0.640 n=6
Check Time 31.96s (± 0.42%) 31.97s (± 0.20%) ~ 31.93s 32.10s p=0.747 n=6
Emit Time 15.17s (± 0.61%) 15.16s (± 0.34%) ~ 15.09s 15.22s p=1.000 n=6
Total Time 55.68s (± 0.46%) 55.69s (± 0.11%) ~ 55.61s 55.75s p=0.575 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,446,316 2,446,316 ~ ~ ~ p=1.000 n=6
Types 897,039 897,040 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,310,632k (± 0.00%) 2,310,620k (± 0.00%) ~ 2,310,588k 2,310,660k p=0.574 n=6
Parse Time 8.95s (± 0.27%) 8.94s (± 0.36%) ~ 8.91s 8.98s p=0.465 n=6
Bind Time 2.11s (± 0.49%) 2.09s (± 0.39%) -0.02s (- 0.95%) 2.08s 2.10s p=0.008 n=6
Check Time 72.98s (± 0.21%) 73.09s (± 0.27%) ~ 72.82s 73.36s p=0.423 n=6
Emit Time 0.28s (± 3.19%) 0.29s (± 2.93%) ~ 0.27s 0.29s p=0.339 n=6
Total Time 84.32s (± 0.20%) 84.41s (± 0.25%) ~ 84.13s 84.66s p=0.575 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 10 🔻+10 (+ ∞%) ~ ~ p=0.001 n=6
Symbols 1,226,880 1,411,602 🔻+184,722 (+15.06%) ~ ~ p=0.001 n=6
Types 266,745 266,918 +173 (+ 0.06%) ~ ~ p=0.001 n=6
Memory used 2,846,600k (±13.19%) 3,274,571k (±12.03%) ~ 2,914,011k 3,634,916k p=0.378 n=6
Parse Time 6.76s (± 1.74%) 11.05s (± 1.19%) 🔻+4.29s (+63.45%) 10.82s 11.17s p=0.005 n=6
Bind Time 2.16s (± 1.34%) 3.78s (± 1.00%) 🔻+1.62s (+75.00%) 3.74s 3.84s p=0.005 n=6
Check Time 42.79s (± 0.70%) 42.49s (± 0.61%) ~ 42.22s 42.82s p=0.128 n=6
Emit Time 3.51s (± 3.19%) 3.44s (± 2.78%) ~ 3.36s 3.60s p=0.378 n=6
Total Time 55.22s (± 0.74%) 60.75s (± 0.61%) 🔻+5.53s (+10.01%) 60.23s 61.15s p=0.005 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 10 🔻+10 (+ ∞%) ~ ~ p=0.001 n=6
Symbols 1,226,880 1,411,602 🔻+184,722 (+15.06%) ~ ~ p=0.001 n=6
Types 266,745 266,918 +173 (+ 0.06%) ~ ~ p=0.001 n=6
Memory used 2,485,671k (± 5.94%) 2,985,643k (± 0.02%) 🔻+499,973k (+20.11%) 2,984,821k 2,986,600k p=0.005 n=6
Parse Time 5.44s (± 0.71%) 9.09s (± 0.64%) 🔻+3.65s (+67.09%) 9.02s 9.18s p=0.005 n=6
Bind Time 1.81s (± 0.75%) 3.14s (± 0.85%) 🔻+1.33s (+73.16%) 3.09s 3.17s p=0.005 n=6
Check Time 35.24s (± 0.75%) 35.15s (± 0.36%) ~ 34.97s 35.36s p=0.173 n=6
Emit Time 3.01s (± 1.06%) 3.07s (± 4.87%) ~ 2.98s 3.37s p=0.936 n=6
Total Time 45.48s (± 0.58%) 50.45s (± 0.41%) 🔻+4.97s (+10.93%) 50.16s 50.75s p=0.005 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 3 🔻+3 (+ ∞%) ~ ~ p=0.001 n=6
Symbols 262,439 262,443 +4 (+ 0.00%) ~ ~ p=0.001 n=6
Types 106,628 106,629 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 440,246k (± 0.01%) 440,327k (± 0.01%) +81k (+ 0.02%) 440,218k 440,420k p=0.031 n=6
Parse Time 3.53s (± 0.64%) 3.55s (± 0.95%) ~ 3.49s 3.59s p=0.250 n=6
Bind Time 1.31s (± 0.62%) 1.32s (± 0.48%) ~ 1.31s 1.33s p=0.177 n=6
Check Time 18.91s (± 0.41%) 18.97s (± 0.24%) ~ 18.94s 19.06s p=0.227 n=6
Emit Time 1.53s (± 1.49%) 1.53s (± 1.23%) ~ 1.50s 1.55s p=0.871 n=6
Total Time 25.28s (± 0.43%) 25.36s (± 0.26%) ~ 25.26s 25.46s p=0.228 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 70 73 🔻+3 (+ 4.29%) ~ ~ p=0.001 n=6
Symbols 226,062 226,062 ~ ~ ~ p=1.000 n=6
Types 94,488 94,490 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 371,582k (± 0.02%) 371,688k (± 0.05%) ~ 371,578k 372,031k p=0.127 n=6
Parse Time 2.90s (± 1.12%) 2.88s (± 0.78%) ~ 2.86s 2.91s p=0.145 n=6
Bind Time 1.59s (± 0.74%) 1.59s (± 0.69%) ~ 1.57s 1.60s p=0.557 n=6
Check Time 16.46s (± 0.48%) 16.55s (± 0.44%) +0.09s (+ 0.55%) 16.42s 16.62s p=0.045 n=6
Emit Time 0.00s 0.00s (±244.70%) ~ 0.00s 0.01s p=0.405 n=6
Total Time 20.96s (± 0.50%) 21.03s (± 0.25%) ~ 20.93s 21.08s p=0.295 n=6
vscode - node (v18.15.0, x64)
Errors 3 18 🔻+15 (+500.00%) ~ ~ p=0.001 n=6
Symbols 3,230,418 3,230,492 +74 (+ 0.00%) ~ ~ p=0.001 n=6
Types 1,112,109 1,112,152 +43 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 3,294,700k (± 0.01%) 3,295,348k (± 0.00%) +648k (+ 0.02%) 3,295,181k 3,295,533k p=0.013 n=6
Parse Time 14.20s (± 0.53%) 14.13s (± 0.33%) ~ 14.07s 14.20s p=0.226 n=6
Bind Time 4.52s (± 0.51%) 4.55s (± 0.49%) ~ 4.53s 4.58s p=0.165 n=6
Check Time 89.02s (± 3.39%) 90.76s (± 2.66%) ~ 87.02s 94.63s p=0.261 n=6
Emit Time 27.54s (± 8.40%) 26.84s (± 7.36%) ~ 22.81s 27.78s p=0.688 n=6
Total Time 135.29s (± 0.85%) 136.28s (± 1.10%) ~ 133.36s 137.35s p=0.092 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 291,562 291,562 ~ ~ ~ p=1.000 n=6
Types 118,971 118,971 ~ ~ ~ p=1.000 n=6
Memory used 445,336k (± 0.02%) 445,361k (± 0.02%) ~ 445,246k 445,454k p=0.689 n=6
Parse Time 5.08s (± 1.11%) 5.06s (± 0.85%) ~ 5.01s 5.13s p=0.687 n=6
Bind Time 2.20s (± 0.45%) 2.20s (± 1.11%) ~ 2.16s 2.22s p=0.802 n=6
Check Time 23.29s (± 0.15%) 23.30s (± 0.65%) ~ 23.06s 23.49s p=0.748 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 30.56s (± 0.31%) 30.56s (± 0.36%) ~ 30.40s 30.69s p=1.000 n=6
xstate-main - node (v18.15.0, x64)
Errors 5 5 ~ ~ ~ p=1.000 n=6
Symbols 555,017 555,017 ~ ~ ~ p=1.000 n=6
Types 186,115 186,115 ~ ~ ~ p=1.000 n=6
Memory used 494,062k (± 0.01%) 494,067k (± 0.01%) ~ 493,980k 494,168k p=1.000 n=6
Parse Time 3.41s (± 0.68%) 3.41s (± 0.93%) ~ 3.37s 3.45s p=1.000 n=6
Bind Time 1.18s (± 1.17%) 1.17s (± 1.29%) ~ 1.15s 1.19s p=0.868 n=6
Check Time 19.52s (± 0.66%) 19.54s (± 0.34%) ~ 19.42s 19.61s p=0.688 n=6
Emit Time 0.00s 0.00s (±244.70%) ~ 0.00s 0.01s p=0.405 n=6
Total Time 24.11s (± 0.63%) 24.13s (± 0.15%) ~ 24.06s 24.16s p=0.810 n=6
System info unknown
Hosts
  • node (v18.15.0, x64)
Scenarios
  • Compiler-Unions - node (v18.15.0, x64)
  • angular-1 - node (v18.15.0, x64)
  • mui-docs - node (v18.15.0, x64)
  • self-build-src - node (v18.15.0, x64)
  • self-build-src-public-api - node (v18.15.0, x64)
  • self-compiler - node (v18.15.0, x64)
  • ts-pre-modules - node (v18.15.0, x64)
  • vscode - node (v18.15.0, x64)
  • webpack - node (v18.15.0, x64)
  • xstate-main - node (v18.15.0, x64)
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@typescript-bot
Copy link
Collaborator

@gabritto Here are the results of running the top 400 repos with tsc comparing main and refs/pull/60068/merge:

Something interesting changed - please have a look.

Details

adobe/react-spectrum

10 of 15 projects failed to build with the old tsc and were ignored

packages/dev/codemods/tsconfig.json

baidu/amis

4 of 5 projects failed to build with the old tsc and were ignored

packages/amis-formula/tsconfig-for-declaration.json

blakeblackshear/frigate

web/tsconfig.json

cheeriojs/cheerio

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

tsconfig.typedoc.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

clash-verge-rev/clash-verge-rev

tsconfig.json

compiler-explorer/compiler-explorer

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

tsconfig.tests.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

tsconfig.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

date-fns/date-fns

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

tsconfig.lib.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

tsconfig.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

desktop/desktop

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

tsconfig.json

ether/etherpad-lite

src/tsconfig.json

formatjs/formatjs

29 of 36 projects failed to build with the old tsc and were ignored

packages/react-intl/integration-tests/tsconfig.json

FuelLabs/fuels-ts

35 of 59 projects failed to build with the old tsc and were ignored

packages/crypto/tsconfig.dts.json

gitpod-io/gitpod

12 of 20 projects failed to build with the old tsc and were ignored

components/gitpod-db/tsconfig.json

google/blockly

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

tsconfig.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

jhipster/generator-jhipster

tsconfig.spec.json

tsconfig.json

konvajs/konva

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

tsconfig.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

microsoft/vscode

5 of 55 projects failed to build with the old tsc and were ignored

src/tsconfig.tsec.json

src/tsconfig.monaco.json

extensions/gulp/tsconfig.json

extensions/emmet/tsconfig.json

@typescript-bot
Copy link
Collaborator

@gabritto Here are some more interesting changes from running the top 400 repos suite

Details

mui/material-ui

23 of 85 projects failed to build with the old tsc and were ignored

test/tsconfig.json

packages-internal/test-utils/tsconfig.json

packages/mui-utils/tsconfig.json

packages/mui-system/tsconfig.json

packages/mui-styles/tsconfig.json

packages/mui-styled-engine-sc/tsconfig.json

packages/mui-styled-engine/tsconfig.json

packages/mui-private-theming/tsconfig.json

packages/mui-material/tsconfig.json

packages/mui-lab/tsconfig.json

packages/mui-joy/tsconfig.json

packages/mui-base/tsconfig.json

packages-internal/test-utils/tsconfig.build.json

openai-translator/openai-translator

tsconfig.json

outline/outline

tsconfig.json

reduxjs/react-redux

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

tsconfig.json

tsconfig.build.json

reduxjs/redux-devtools

25 of 58 projects failed to build with the old tsc and were ignored

packages/d3-state-visualizer/tsconfig.json

extension/tsconfig.json

redwoodjs/redwood

66 of 105 projects failed to build with the old tsc and were ignored

packages/router/tsconfig.cjs.json

refined-github/refined-github

tsconfig.json

signalapp/Signal-Desktop

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

sticker-creator/tsconfig.json

@typescript-bot
Copy link
Collaborator

@gabritto Here are some more interesting changes from running the top 400 repos suite

Details

tinacms/tinacms

12 of 24 projects failed to build with the old tsc and were ignored

packages/@tinacms/mdx/tsconfig.json

tusen-ai/naive-ui

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

src/tsconfig.demo.json

vercel/swr

6 of 8 projects failed to build with the old tsc and were ignored

tsconfig.json

  • error TS2774: This condition will always return true since this function is always defined. Did you mean to call it instead?

video-dev/hls.js

tsconfig.json

@tjenkinson
Copy link
Contributor Author

  1. https://github.com/webpack/webpack/blob/3919c844eca394d73ca930e4fc5506fb86e2b094/lib/NormalModule.js#L831 think think this is fine, identifier should be optional
  2. https://github.com/webpack/webpack/blob/3919c844eca394d73ca930e4fc5506fb86e2b094/lib/dependencies/LoaderPlugin.js#L277 it's a js file and doesn't infer that callback could be undefined. I think this is fine? They add a jsdoc type or another ts-ignore
  3. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/de59f128691d22d9bf25ed2b659acae6c50629b1/types/morgan/morgan-tests.ts#L88 is interesting. It's failing because even though it's let fn: morgan.FormatFn | undefined = developmentExtendedFormatLine.memoizer[color]; it's thinking it can't be undefined given it assumes the array access will always find something. I think let fn = developmentExtendedFormatLine.memoizer[color] as morgan.FormatFn | undefined; would fix this
  4. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/de59f128691d22d9bf25ed2b659acae6c50629b1/types/activex-excel/activex-excel-tests.ts#L98. Not sure. Maybe the types or test is wrong
  5. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/de59f128691d22d9bf25ed2b659acae6c50629b1/types/xdate/xdate-tests.ts#L1177 is expected. If the check was inverted it would be fine 🤔
  6. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/de59f128691d22d9bf25ed2b659acae6c50629b1/types/js-fixtures/js-fixtures-tests.ts#L16 maybe the types are wrong, or this is a case where would opt out with !!! or use as
  7. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/de59f128691d22d9bf25ed2b659acae6c50629b1/types/yandex-maps/yandex-maps-tests.ts#L162 is expected. If the check was inverted it would be fine
  8. https://github.com/DefinitelyTyped/DefinitelyTyped/blob/de59f128691d22d9bf25ed2b659acae6c50629b1/types/activex-shell/activex-shell-tests.ts#L426. This one shouldn't be failing. Need to figure out why
  9. https://github.com/adobe/react-spectrum/blob/4dd0993da6421c14a632b7d0a11b17e759eef38c/packages/dev/codemods/src/index.ts#L86 is expected. If the check was inverted it would be fine
  10. https://github.com/baidu/amis/blob/2747feea574344346afdc53940c42547e98f91c7/packages/amis-formula/src/evalutor.ts#L74 is expected. If the check was inverted it would be fine
  11. https://github.com/baidu/amis/blob/2747feea574344346afdc53940c42547e98f91c7/packages/amis-formula/src/evalutor.ts#L118 is expected. If the check was inverted it would be fine
  12. https://github.com/blakeblackshear/frigate/blob/a1ce9aacf27591d141619e887579c963df55ce8e/web/src/components/player/WebRTCPlayer.tsx#L109 looks like a real bug. I think the type should be Promise<RTCPeerConnection> | undefined instead of Promise<RTCPeerConnection | undefined>
  13. https://github.com/cheeriojs/cheerio/blob/418e98b0f448a7ff470055a3d0cbe61e72605d41/src/static.ts#L26 is expected. If the check was inverted it would be fine
  14. https://github.com/clash-verge-rev/clash-verge-rev/blob/ae5b2cfb79423c7e76a281725209b812774367fa/src/components/setting/mods/password-input.tsx#L23 looks like a mistake
  15. https://github.com/compiler-explorer/compiler-explorer/blob/b97cbb33b9605082c326cfe7d22aa577193754e8/lib/exec.ts#L412 is expected. If the check was inverted it would be fine
  16. https://github.com/compiler-explorer/compiler-explorer/blob/b97cbb33b9605082c326cfe7d22aa577193754e8/lib/exec.ts#L630 is expected. If the check was inverted it would be fine
  17. https://github.com/compiler-explorer/compiler-explorer/blob/b97cbb33b9605082c326cfe7d22aa577193754e8/lib/exec.ts#L412 is expected. If the check was inverted it would be fine
  18. https://github.com/compiler-explorer/compiler-explorer/blob/b97cbb33b9605082c326cfe7d22aa577193754e8/lib/exec.ts#L630 is expected. If the check was inverted it would be fine

.. started skimming through the rest

  1. https://github.com/desktop/desktop/blob/80ac47dc75d308d562c45d97c31dfee86226d3f4/app/src/lib/git/cherry-pick.ts#L219 looks like real bug
  2. https://github.com/desktop/desktop/blob/80ac47dc75d308d562c45d97c31dfee86226d3f4/app/src/lib/stores/app-store.ts#L7248 looks like real bug
  3. https://github.com/ether/etherpad-lite/blob/13bc06febea15b6d816a125d4c2ca7ceedcf4c58/src/static/js/caretPosition.ts#L194 is expected. If the check was inverted it would be fine
  4. https://github.com/gitpod-io/gitpod/blob/4c25f426e1d1c911099e51ad3771143ca380f32c/components/gitpod-db/src/typeorm/migration/helper/helper.ts#L19 looks like a real bug

(5) (7) (9) (10) (11) (13) (15) (16) (17) (18) (22) would be fine if we check if the variable is called/awaited/assigned to anywhere inside the enclosing function

(3) (10) (15) (16) (17) (18) are issues where array access is not also undefined

So I think we'll need to do something like

would be fine if we check if the variable is called/awaited/assigned to anywhere inside the enclosing function

?

Wondering if you have any other ideas or if there could be a performance issue with this? @gabritto

Copy link
Member

@gabritto gabritto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some questions, but also, can you add some tests so we can track which cases are currently supported and which are not, and which are potential false errors? Otherwise, it's hard for me to remember in between reviews.

@@ -44588,8 +44593,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
return;
}

const isUsedInBody = inverted && isIfStatement(condExpr.parent) ? testedSymbol && isSymbolUsedInConditionBody(location, condExpr.parent.parent, testedNode, testedSymbol, /*checkForAssignment*/ true) : testedSymbol && body && isSymbolUsedInConditionBody(condExpr, body, testedNode, testedSymbol, /*checkForAssignment*/ false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we call isSymbolUsedInConditionBody with location instead of condExpr, in the first case?


function next() {
let task = tasks[index]
if (!task) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This case looks like a bug in your PR code: we should not be erroring because task is used inside the else block.

@@ -44606,15 +44613,23 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}
}

function isSymbolUsedInConditionBody(expr: Expression, body: Statement | Expression, testedNode: Node, testedSymbol: Symbol): boolean {
function isSymbolUsedInConditionBody(expr: Expression, body: Statement | Expression | Node, testedNode: Node, testedSymbol: Symbol, checkForAssignment: boolean): boolean {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the idea here behind checkForAssignment? Why were the previous checks being done here in isSymbolUsedInConditionBody not enough?

const location = isLogicalOrCoalescingBinaryExpression(condExpr) ? skipParentheses(condExpr.right) : condExpr;
let location = condExpr;
let inverted = false;
if (isPrefixUnaryExpression(location)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you also need to check that the operator is the exclamation token. Otherwise location could be another kind of expression, e.g. ++a.

let inverted = false;
if (isPrefixUnaryExpression(location)) {
location = skipParentheses(location.operand);
inverted = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing to consider (and probably add a test) is that we can have an expression that flips between the negative and positive case, if we have nested negation expressions, e.g.: if (a && !(b || !c)) ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inverted Promise should warn like it does without inverting
3 participants