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

Support interpreting non-literal computed properties in classes as implicit index signatures #59860

Merged
merged 8 commits into from
Sep 23, 2024

Conversation

weswigham
Copy link
Member

Instead of silently dropping them (if they're declared by methods) as we do today.

This still has some minor issues and open questions, but is far enough along to share and talk about. Today, when you have a class like

declare const a: symbol;
export class A {
    [a]() { return 1 };
}

that's just fine - no errors anywhere. But if you add a

declare const e1: A[typeof a];

you get an error that A has no symbol index signature. What's up with that? Well, we dropped the [a] member entirely, silently. There are historical reasons for this, but they don't really hold much weight nowadays beyond "for back compat". Under non-strict, this can actually be insidious, as when you use an expression, the (new A())[a] expression can silently be any, since under non-strict mode, non-existing element accesses resolve to any without error. With this PR, A[typeof a] instead resolves to () => number (the method's type) as we've created an implicit index signature for the computed name, just like we do for object literals.

Technically, this involves late-binding the __index member of the class like we do other computed literal names (so you could call these "late bound index signatures" as I do in the code), but that's not so important compared to the effect. This is pretty different from how these kinds of indexes are built for object literals, but that's because object literals are built somewhat on-demand from their constituent declarations, rather than having a big table of declared metadata built up-front like classes and interfaces do.

The big questions I'm still considering are:

  • Should all the indexes for the same key types get combined? Right now for objects they do, but in the implementation, the first one decides the signature type and errors are issued on any others that don't match. (Is our behavior for objects good?)
  • Should the error on non-literal computed properties, A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type.(1166) be removed, too? Methods don't emit an error, which is what motivated me here, but all this logic equally applies to properties, so the error doesn't make too much sense for them now.
  • Should this require opt-in via noImplicitAny or another (strict?) flag? (preferably not - this being flagged somewhat defeats the point, imo)

And, ofc, this needs more tests, covering other key types (unions, pattern literals) and modifiers (static, readonly) on the computed names (though I've informally handled them in the code, I think) before this can actually be merged (though these probably have some coverage already from documenting our current behavior - they could stand to be more comprehensive).

This is, IMO, a worthwhile step towards unifying all of our computed property name behaviors. In an ideal world, a computed property name in a class, object, in a source or declaration file, could all be interpreted the same way (and thus, it could always be safe to copy one from one place or file kind into the other). Unfortunately, today we have some behavioral carve-outs from the time before we even meaningfully supported literal types, or even had --strict, that get in the way of that, like this.

@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Sep 4, 2024
@weswigham
Copy link
Member Author

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 4, 2024

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

Command Status Results
pack this ✅ Started ✅ Results

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 4, 2024

Hey @weswigham, 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/163508/artifacts?artifactName=tgz&fileId=BC8EAA3AB4A7092D73B64AB5D33BC556C27F8482F31A3222954DD7E6A6A4573002&fileName=/typescript-5.7.0-insiders.20240904.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/pr-build@5.7.0-pr-59860-2".;

@weswigham
Copy link
Member Author

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 6, 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 @weswigham, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

@weswigham
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,153 62,153 ~ ~ ~ p=1.000 n=6
Types 50,242 50,242 ~ ~ ~ p=1.000 n=6
Memory used 194,194k (± 0.98%) 193,647k (± 0.98%) ~ 192,379k 196,219k p=0.689 n=6
Parse Time 1.31s (± 0.31%) 1.31s (± 0.75%) ~ 1.29s 1.32s p=0.753 n=6
Bind Time 0.71s 0.71s ~ ~ ~ p=1.000 n=6
Check Time 9.56s (± 0.48%) 9.58s (± 0.25%) ~ 9.54s 9.61s p=0.517 n=6
Emit Time 2.74s (± 0.60%) 2.72s (± 0.63%) ~ 2.70s 2.75s p=0.164 n=6
Total Time 14.31s (± 0.45%) 14.32s (± 0.23%) ~ 14.27s 14.36s p=1.000 n=6
angular-1 - node (v18.15.0, x64)
Errors 7 11 🔻+4 (+57.14%) ~ ~ p=0.001 n=6
Symbols 945,753 945,755 +2 (+ 0.00%) ~ ~ p=0.001 n=6
Types 410,067 410,072 +5 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 1,222,741k (± 0.00%) 1,222,807k (± 0.00%) +65k (+ 0.01%) 1,222,775k 1,222,872k p=0.005 n=6
Parse Time 6.63s (± 0.70%) 6.65s (± 0.39%) ~ 6.62s 6.69s p=0.572 n=6
Bind Time 1.86s (± 0.40%) 1.86s (± 0.28%) ~ 1.86s 1.87s p=0.784 n=6
Check Time 31.17s (± 0.25%) 31.31s (± 0.43%) ~ 31.11s 31.49s p=0.078 n=6
Emit Time 15.06s (± 0.16%) 15.04s (± 0.44%) ~ 14.97s 15.15s p=0.519 n=6
Total Time 54.73s (± 0.18%) 54.87s (± 0.12%) +0.14s (+ 0.25%) 54.79s 54.97s p=0.020 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,505,962 2,505,962 ~ ~ ~ p=1.000 n=6
Types 932,873 932,873 ~ ~ ~ p=1.000 n=6
Memory used 2,334,309k (± 0.00%) 2,334,335k (± 0.00%) ~ 2,334,247k 2,334,488k p=0.336 n=6
Parse Time 9.24s (± 0.16%) 9.26s (± 0.21%) ~ 9.24s 9.29s p=0.162 n=6
Bind Time 2.17s (± 0.61%) 2.16s (± 0.91%) ~ 2.12s 2.17s p=0.145 n=6
Check Time 72.58s (± 0.35%) 72.60s (± 0.34%) ~ 72.27s 72.88s p=0.936 n=6
Emit Time 0.28s (± 2.95%) 0.28s (± 1.86%) ~ 0.27s 0.28s p=0.752 n=6
Total Time 84.27s (± 0.29%) 84.30s (± 0.30%) ~ 83.97s 84.57s p=0.936 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,247,048 1,247,344 +296 (+ 0.02%) ~ ~ p=0.001 n=6
Types 265,107 265,257 +150 (+ 0.06%) ~ ~ p=0.001 n=6
Memory used 2,398,167k (± 0.01%) 2,398,870k (± 0.01%) +703k (+ 0.03%) 2,398,532k 2,399,143k p=0.005 n=6
Parse Time 5.03s (± 0.49%) 5.01s (± 0.81%) ~ 4.94s 5.05s p=0.809 n=6
Bind Time 1.94s (± 0.53%) 1.93s (± 0.60%) ~ 1.92s 1.95s p=0.456 n=6
Check Time 34.91s (± 0.34%) 34.90s (± 0.21%) ~ 34.83s 35.03s p=0.936 n=6
Emit Time 3.31s (± 1.33%) 3.30s (± 0.78%) ~ 3.27s 3.33s p=0.572 n=6
Total Time 45.19s (± 0.26%) 45.15s (± 0.18%) ~ 45.06s 45.26s p=0.810 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,247,048 1,247,344 +296 (+ 0.02%) ~ ~ p=0.001 n=6
Types 265,107 265,257 +150 (+ 0.06%) ~ ~ p=0.001 n=6
Memory used 2,472,724k (± 0.03%) 2,473,350k (± 0.02%) ~ 2,472,808k 2,473,969k p=0.093 n=6
Parse Time 7.85s (± 0.78%) 7.82s (± 0.60%) ~ 7.78s 7.90s p=0.471 n=6
Bind Time 2.56s (± 0.48%) 2.54s (± 0.43%) ~ 2.53s 2.56s p=0.096 n=6
Check Time 50.95s (± 0.35%) 51.20s (± 0.62%) ~ 50.91s 51.76s p=0.128 n=6
Emit Time 4.92s (± 1.10%) 4.96s (± 1.80%) ~ 4.86s 5.12s p=0.471 n=6
Total Time 66.28s (± 0.32%) 66.53s (± 0.46%) ~ 66.17s 67.06s p=0.229 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 259,129 259,359 +230 (+ 0.09%) ~ ~ p=0.001 n=6
Types 105,985 106,135 +150 (+ 0.14%) ~ ~ p=0.001 n=6
Memory used 433,699k (± 0.05%) 433,874k (± 0.03%) ~ 433,741k 434,072k p=0.128 n=6
Parse Time 3.42s (± 0.71%) 3.41s (± 0.63%) ~ 3.38s 3.44s p=0.332 n=6
Bind Time 1.27s (± 0.66%) 1.28s (± 1.10%) ~ 1.26s 1.30s p=0.503 n=6
Check Time 18.12s (± 0.24%) 18.06s (± 0.19%) ~ 18.01s 18.10s p=0.054 n=6
Emit Time 1.68s (± 1.11%) 1.67s (± 1.40%) ~ 1.64s 1.70s p=0.871 n=6
Total Time 24.50s (± 0.18%) 24.43s (± 0.11%) -0.07s (- 0.30%) 24.39s 24.46s p=0.010 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 68 68 ~ ~ ~ p=1.000 n=6
Symbols 225,018 225,018 ~ ~ ~ p=1.000 n=6
Types 94,249 94,249 ~ ~ ~ p=1.000 n=6
Memory used 370,246k (± 0.02%) 370,316k (± 0.02%) ~ 370,217k 370,437k p=0.173 n=6
Parse Time 2.77s (± 0.99%) 2.75s (± 0.78%) ~ 2.73s 2.79s p=0.157 n=6
Bind Time 1.57s (± 1.25%) 1.57s (± 0.74%) ~ 1.56s 1.59s p=0.863 n=6
Check Time 15.78s (± 0.45%) 15.78s (± 0.63%) ~ 15.60s 15.88s p=1.000 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.13s (± 0.46%) 20.10s (± 0.43%) ~ 19.96s 20.20s p=0.809 n=6
vscode - node (v18.15.0, x64)
Errors 1 1 ~ ~ ~ p=1.000 n=6
Symbols 3,041,336 3,041,337 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 1,051,617 1,051,617 ~ ~ ~ p=1.000 n=6
Memory used 3,149,210k (± 0.00%) 3,149,235k (± 0.00%) ~ 3,149,071k 3,149,345k p=0.689 n=6
Parse Time 13.80s (± 0.35%) 13.81s (± 0.58%) ~ 13.69s 13.93s p=0.872 n=6
Bind Time 4.42s (± 2.41%) 4.43s (± 2.81%) ~ 4.31s 4.58s p=1.000 n=6
Check Time 81.18s (± 0.27%) 81.49s (± 0.46%) ~ 80.75s 81.77s p=0.065 n=6
Emit Time 22.10s (± 0.71%) 22.00s (± 0.56%) ~ 21.81s 22.17s p=0.471 n=6
Total Time 121.50s (± 0.28%) 121.73s (± 0.46%) ~ 120.65s 122.12s p=0.229 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 277,017 277,018 +1 (+ 0.00%) ~ ~ p=0.001 n=6
Types 112,816 112,816 ~ ~ ~ p=1.000 n=6
Memory used 426,811k (± 0.03%) 426,779k (± 0.02%) ~ 426,665k 426,882k p=0.810 n=6
Parse Time 4.90s (± 0.42%) 4.88s (± 0.31%) ~ 4.87s 4.91s p=0.256 n=6
Bind Time 2.14s (± 0.82%) 2.15s (± 1.44%) ~ 2.10s 2.18s p=1.000 n=6
Check Time 21.79s (± 0.48%) 21.70s (± 0.43%) ~ 21.57s 21.83s p=0.149 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 28.83s (± 0.37%) 28.73s (± 0.26%) ~ 28.63s 28.81s p=0.106 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 539,317 539,317 ~ ~ ~ p=1.000 n=6
Types 178,997 178,997 ~ ~ ~ p=1.000 n=6
Memory used 484,147k (± 0.03%) 484,064k (± 0.03%) ~ 483,872k 484,249k p=0.378 n=6
Parse Time 4.26s (± 0.39%) 4.24s (± 0.32%) -0.02s (- 0.55%) 4.22s 4.26s p=0.033 n=6
Bind Time 1.55s (± 1.05%) 1.55s (± 0.75%) ~ 1.54s 1.57s p=1.000 n=6
Check Time 22.51s (± 0.33%) 22.56s (± 0.45%) ~ 22.43s 22.65s p=0.336 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 28.33s (± 0.29%) 28.35s (± 0.34%) ~ 28.22s 28.44s p=0.809 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

@jakebailey
Copy link
Member

Seems like the angular codebase is gaining new errors?

@typescript-bot
Copy link
Collaborator

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

Something interesting changed - please have a look.

Details

jhipster/generator-jhipster

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

tsconfig.json

  • error TS2411: Property 'baseName' of type 'string' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "convertToJDL">'.
  • error TS2411: Property 'jdlFile' of type 'string' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "convertToJDL">'.
  • error TS2411: Property 'jdlContent' of type 'string | undefined' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "convertToJDL">'.
  • error TS2411: Property '[BaseGenerator.WRITING]' of type 'GenericTaskGroup<any, TaskParamWithControl, "writeJdl">' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "convertToJDL">'.
  • error TS2411: Property '[BaseGenerator.END]' of type 'GenericTaskGroup<any, TaskParamWithControl, "end">' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "convertToJDL">'.
  • error TS2411: Property 'checkCommand' of type '(command: string, args: string[], printInfo?: (result: { stdout: string; stderr: string; }) => void) => Promise<void>' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "checkGit" | "sayHello" | "checkJHipster" | "displayConfiguration" | "checkJava" | "checkNode" | "checkNpm" | "checkDocker" | "checkApplication" | "displayEntities">'.
  • error TS2411: Property 'generateJDLFromEntities' of type '() => any' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "checkGit" | "sayHello" | "checkJHipster" | "displayConfiguration" | "checkJava" | "checkNode" | "checkNpm" | "checkDocker" | "checkApplication" | "displayEntities">'.
  • error TS2411: Property 'beforeQueue' of type '() => Promise<void>' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "askForServerTestOpts" | "askForServerSideOpts" | "askForOptionalItems">'.
  • error TS2411: Property 'writingEntities' of type 'GenericTaskGroup<any, TaskParamWithEntities<Entity<Field, never>, ApplicationType<Entity<Field, never>>>, "writeServerFiles" | "cleanupOldServerFiles">' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "askForServerTestOpts" | "askForServerSideOpts" | "askForOptionalItems">'.
  • error TS2411: Property '[BaseApplicationGenerator.WRITING_ENTITIES]' of type 'GenericTaskGroup<any, TaskParamWithEntities<Entity<Field, never>, ApplicationType<Entity<Field, never>>>, "writeServerFiles" | "cleanupOldServerFiles">' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "askForServerTestOpts" | "askForServerSideOpts" | "askForOptionalItems">'.
  • error TS2411: Property 'getPrimaryKeyValue' of type '(primaryKey: any, databaseType?: any, defaultValue?: number) => string' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "askForServerTestOpts" | "askForServerSideOpts" | "askForOptionalItems">'.

@weswigham
Copy link
Member Author

@typescript-bot test it

Now I'm using exactly the same index signature creation logic we use for object literal expressions, with all of it's flaws (like making a lot of number index signatures you may not expect). Let's see how this goes.

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 9, 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 @weswigham, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

@weswigham
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,153 62,153 ~ ~ ~ p=1.000 n=6
Types 50,242 50,242 ~ ~ ~ p=1.000 n=6
Memory used 193,574k (± 0.93%) 193,071k (± 0.73%) ~ 192,407k 195,949k p=0.936 n=6
Parse Time 1.58s (± 0.93%) 1.57s (± 0.87%) ~ 1.55s 1.59s p=0.510 n=6
Bind Time 0.86s (± 1.04%) 0.86s (± 1.27%) ~ 0.85s 0.87s p=1.000 n=6
Check Time 11.36s (± 0.47%) 11.40s (± 0.38%) ~ 11.35s 11.47s p=0.090 n=6
Emit Time 3.25s (± 0.75%) 3.24s (± 0.95%) ~ 3.20s 3.28s p=0.516 n=6
Total Time 17.04s (± 0.42%) 17.07s (± 0.47%) ~ 16.96s 17.17s p=0.686 n=6
angular-1 - node (v18.15.0, x64)
Errors 7 11 🔻+4 (+57.14%) ~ ~ p=0.001 n=6
Symbols 945,753 945,762 +9 (+ 0.00%) ~ ~ p=0.001 n=6
Types 410,067 410,075 +8 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 1,222,717k (± 0.00%) 1,222,759k (± 0.00%) ~ 1,222,662k 1,222,829k p=0.173 n=6
Parse Time 7.92s (± 0.53%) 7.93s (± 0.31%) ~ 7.90s 7.95s p=0.744 n=6
Bind Time 2.23s (± 0.23%) 2.23s (± 0.38%) ~ 2.22s 2.24s p=0.533 n=6
Check Time 36.35s (± 0.41%) 36.56s (± 0.44%) ~ 36.39s 36.77s p=0.054 n=6
Emit Time 17.88s (± 0.53%) 17.86s (± 0.22%) ~ 17.79s 17.91s p=0.419 n=6
Total Time 64.38s (± 0.30%) 64.57s (± 0.26%) ~ 64.37s 64.74s p=0.127 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,506,932 2,506,986 +54 (+ 0.00%) ~ ~ p=0.001 n=6
Types 932,998 933,017 +19 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,336,489k (± 0.00%) 2,336,552k (± 0.00%) ~ 2,336,495k 2,336,618k p=0.173 n=6
Parse Time 11.01s (± 0.29%) 11.01s (± 0.28%) ~ 10.95s 11.04s p=1.000 n=6
Bind Time 2.57s (± 0.94%) 2.57s (± 0.55%) ~ 2.55s 2.59s p=0.745 n=6
Check Time 85.98s (± 0.32%) 86.17s (± 0.39%) ~ 85.62s 86.50s p=0.336 n=6
Emit Time 0.32s (± 2.34%) 0.34s (± 1.53%) 🔻+0.01s (+ 4.66%) 0.33s 0.34s p=0.010 n=6
Total Time 99.89s (± 0.29%) 100.09s (± 0.32%) ~ 99.55s 100.41s p=0.230 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,250,213 1,250,555 +342 (+ 0.03%) ~ ~ p=0.001 n=6
Types 265,146 265,304 +158 (+ 0.06%) ~ ~ p=0.001 n=6
Memory used 2,402,574k (± 0.02%) 2,403,217k (± 0.03%) ~ 2,402,219k 2,403,761k p=0.128 n=6
Parse Time 6.09s (± 0.79%) 6.11s (± 0.61%) ~ 6.08s 6.17s p=0.689 n=6
Bind Time 2.26s (± 0.81%) 2.29s (± 1.48%) ~ 2.25s 2.33s p=0.125 n=6
Check Time 41.23s (± 1.07%) 41.10s (± 0.57%) ~ 40.80s 41.35s p=0.378 n=6
Emit Time 3.97s (± 1.11%) 4.00s (± 3.73%) ~ 3.88s 4.29s p=0.689 n=6
Total Time 53.57s (± 0.90%) 53.50s (± 0.51%) ~ 53.11s 53.79s p=0.575 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,250,213 1,250,555 +342 (+ 0.03%) ~ ~ p=0.001 n=6
Types 265,146 265,304 +158 (+ 0.06%) ~ ~ p=0.001 n=6
Memory used 2,477,482k (± 0.02%) 2,477,718k (± 0.02%) ~ 2,477,053k 2,478,317k p=0.378 n=6
Parse Time 7.82s (± 0.98%) 7.84s (± 0.65%) ~ 7.79s 7.92s p=0.810 n=6
Bind Time 2.52s (± 0.54%) 2.54s (± 0.75%) ~ 2.52s 2.57s p=0.197 n=6
Check Time 51.24s (± 0.77%) 51.13s (± 0.72%) ~ 50.78s 51.78s p=0.471 n=6
Emit Time 4.96s (± 0.77%) 5.03s (± 3.72%) ~ 4.89s 5.40s p=0.810 n=6
Total Time 66.54s (± 0.53%) 66.57s (± 0.56%) ~ 66.21s 67.24s p=0.873 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 259,449 259,685 +236 (+ 0.09%) ~ ~ p=0.001 n=6
Types 105,986 106,135 +149 (+ 0.14%) ~ ~ p=0.001 n=6
Memory used 433,838k (± 0.02%) 434,199k (± 0.02%) +360k (+ 0.08%) 434,085k 434,366k p=0.005 n=6
Parse Time 4.21s (± 0.84%) 4.24s (± 1.04%) ~ 4.16s 4.29s p=0.293 n=6
Bind Time 1.57s (± 1.31%) 1.57s (± 0.70%) ~ 1.56s 1.59s p=0.933 n=6
Check Time 22.36s (± 0.25%) 22.38s (± 0.33%) ~ 22.24s 22.46s p=0.418 n=6
Emit Time 2.04s (± 1.14%) 2.02s (± 0.99%) -0.02s (- 1.14%) 1.98s 2.03s p=0.040 n=6
Total Time 30.20s (± 0.19%) 30.21s (± 0.35%) ~ 30.02s 30.32s p=0.470 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 68 68 ~ ~ ~ p=1.000 n=6
Symbols 225,018 225,018 ~ ~ ~ p=1.000 n=6
Types 94,249 94,249 ~ ~ ~ p=1.000 n=6
Memory used 370,218k (± 0.02%) 370,252k (± 0.02%) ~ 370,176k 370,333k p=0.229 n=6
Parse Time 3.45s (± 1.07%) 3.42s (± 0.55%) ~ 3.39s 3.44s p=0.124 n=6
Bind Time 1.92s (± 0.51%) 1.93s (± 0.87%) ~ 1.91s 1.96s p=0.315 n=6
Check Time 19.44s (± 0.27%) 19.46s (± 0.51%) ~ 19.33s 19.60s p=0.630 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 24.81s (± 0.26%) 24.81s (± 0.38%) ~ 24.70s 24.95s p=0.810 n=6
vscode - node (v18.15.0, x64)
Errors 1 1 ~ ~ ~ p=1.000 n=6
Symbols 3,041,319 3,041,378 +59 (+ 0.00%) ~ ~ p=0.001 n=6
Types 1,051,797 1,051,818 +21 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 3,149,846k (± 0.00%) 3,149,913k (± 0.00%) +68k (+ 0.00%) 3,149,883k 3,149,982k p=0.030 n=6
Parse Time 13.77s (± 0.28%) 13.84s (± 0.52%) ~ 13.75s 13.94s p=0.090 n=6
Bind Time 4.45s (± 2.63%) 4.49s (± 2.40%) ~ 4.35s 4.58s p=0.328 n=6
Check Time 81.60s (± 0.33%) 81.63s (± 0.49%) ~ 81.02s 82.00s p=1.000 n=6
Emit Time 22.11s (± 0.37%) 22.03s (± 0.87%) ~ 21.87s 22.39s p=0.173 n=6
Total Time 121.92s (± 0.23%) 121.99s (± 0.38%) ~ 121.41s 122.56s p=0.689 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 277,022 276,955 -67 (- 0.02%) ~ ~ p=0.001 n=6
Types 112,817 112,973 +156 (+ 0.14%) ~ ~ p=0.001 n=6
Memory used 426,673k (± 0.02%) 426,816k (± 0.02%) +143k (+ 0.03%) 426,713k 426,917k p=0.020 n=6
Parse Time 3.95s (± 0.44%) 3.95s (± 0.41%) ~ 3.93s 3.97s p=0.869 n=6
Bind Time 1.71s (± 0.24%) 1.71s (± 1.01%) ~ 1.68s 1.73s p=0.528 n=6
Check Time 17.59s (± 0.39%) 17.58s (± 0.52%) ~ 17.47s 17.69s p=0.574 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 23.26s (± 0.26%) 23.24s (± 0.49%) ~ 23.11s 23.38s p=0.689 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 539,317 539,355 +38 (+ 0.01%) ~ ~ p=0.001 n=6
Types 178,997 179,004 +7 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 484,293k (± 0.02%) 484,268k (± 0.04%) ~ 483,947k 484,472k p=0.936 n=6
Parse Time 2.84s (± 0.56%) 2.84s (± 0.44%) ~ 2.82s 2.85s p=0.869 n=6
Bind Time 1.05s (± 0.78%) 1.05s ~ ~ ~ p=0.405 n=6
Check Time 15.49s (± 0.41%) 15.76s (± 0.28%) +0.27s (+ 1.73%) 15.71s 15.82s p=0.005 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 19.37s (± 0.34%) 19.64s (± 0.21%) +0.27s (+ 1.39%) 19.60s 19.70s p=0.005 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

@weswigham
Copy link
Member Author

Hm. Still some new errors in angular, but everything else looks fine now. Guess I'll have to look at what those are.

@typescript-bot
Copy link
Collaborator

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

Something interesting changed - please have a look.

Details

jhipster/generator-jhipster

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

tsconfig.json

  • error TS2411: Property 'baseName' of type 'string' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "convertToJDL"> | GenericTaskGroup<any, TaskParamWithControl, "writeJdl"> | GenericTaskGroup<...>'.
  • error TS2411: Property 'jdlFile' of type 'string' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "convertToJDL"> | GenericTaskGroup<any, TaskParamWithControl, "writeJdl"> | GenericTaskGroup<...>'.
  • error TS2411: Property 'jdlContent' of type 'string | undefined' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "convertToJDL"> | GenericTaskGroup<any, TaskParamWithControl, "writeJdl"> | GenericTaskGroup<...>'.
  • error TS2411: Property 'checkCommand' of type '(command: string, args: string[], printInfo?: (result: { stdout: string; stderr: string; }) => void) => Promise<void>' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "checkGit" | "sayHello" | "checkJHipster" | "displayConfiguration" | "checkJava" | "checkNode" | "checkNpm" | "checkDocker" | "checkApplication" | "displayEntities">'.
  • error TS2411: Property 'generateJDLFromEntities' of type '() => any' is not assignable to 'string' index type 'GenericTaskGroup<any, TaskParamWithControl, "checkGit" | "sayHello" | "checkJHipster" | "displayConfiguration" | "checkJava" | "checkNode" | "checkNpm" | "checkDocker" | "checkApplication" | "displayEntities">'.

@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

@weswigham
Copy link
Member Author

@typescript-bot test it

@typescript-bot
Copy link
Collaborator

typescript-bot commented Sep 10, 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 @weswigham, the results of running the DT tests are ready.

Everything looks the same!

You can check the log here.

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@typescript-bot
Copy link
Collaborator

@weswigham
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,153 62,153 ~ ~ ~ p=1.000 n=6
Types 50,242 50,242 ~ ~ ~ p=1.000 n=6
Memory used 193,052k (± 0.77%) 193,051k (± 0.75%) ~ 192,436k 196,011k p=0.298 n=6
Parse Time 1.30s (± 0.84%) 1.31s (± 0.39%) ~ 1.30s 1.31s p=0.321 n=6
Bind Time 0.71s 0.71s ~ ~ ~ p=1.000 n=6
Check Time 9.58s (± 0.55%) 9.58s (± 0.27%) ~ 9.55s 9.62s p=0.936 n=6
Emit Time 2.72s (± 0.49%) 2.72s (± 0.95%) ~ 2.69s 2.76s p=0.935 n=6
Total Time 14.31s (± 0.38%) 14.31s (± 0.29%) ~ 14.26s 14.38s p=0.936 n=6
angular-1 - node (v18.15.0, x64)
Errors 7 7 ~ ~ ~ p=1.000 n=6
Symbols 945,753 945,758 +5 (+ 0.00%) ~ ~ p=0.001 n=6
Types 410,067 410,073 +6 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 1,222,743k (± 0.00%) 1,222,820k (± 0.00%) ~ 1,222,788k 1,222,838k p=0.066 n=6
Parse Time 6.62s (± 0.31%) 6.67s (± 0.34%) +0.05s (+ 0.78%) 6.65s 6.71s p=0.006 n=6
Bind Time 1.87s (± 0.29%) 1.86s (± 0.53%) ~ 1.84s 1.87s p=0.201 n=6
Check Time 31.18s (± 0.33%) 31.29s (± 0.52%) ~ 31.10s 31.52s p=0.261 n=6
Emit Time 15.00s (± 0.77%) 15.01s (± 0.64%) ~ 14.83s 15.11s p=0.936 n=6
Total Time 54.67s (± 0.14%) 54.82s (± 0.44%) ~ 54.54s 55.20s p=0.296 n=6
mui-docs - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 2,515,550 2,515,604 +54 (+ 0.00%) ~ ~ p=0.001 n=6
Types 933,023 933,042 +19 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 2,350,381k (± 0.01%) 2,350,413k (± 0.00%) ~ 2,350,332k 2,350,529k p=0.298 n=6
Parse Time 9.43s (± 0.30%) 9.43s (± 0.28%) ~ 9.39s 9.46s p=0.936 n=6
Bind Time 2.18s (± 0.34%) 2.17s (± 0.38%) ~ 2.16s 2.18s p=0.120 n=6
Check Time 73.11s (± 1.41%) 73.06s (± 0.48%) ~ 72.56s 73.48s p=0.470 n=6
Emit Time 0.28s 0.28s (± 2.95%) ~ 0.27s 0.29s p=0.290 n=6
Total Time 85.00s (± 1.25%) 84.93s (± 0.40%) ~ 84.49s 85.38s p=0.230 n=6
self-build-src - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,250,213 1,250,582 +369 (+ 0.03%) ~ ~ p=0.001 n=6
Types 265,146 265,307 +161 (+ 0.06%) ~ ~ p=0.001 n=6
Memory used 2,427,967k (± 2.59%) 2,403,188k (± 0.03%) ~ 2,402,166k 2,403,855k p=0.378 n=6
Parse Time 6.10s (± 0.42%) 6.15s (± 0.35%) +0.04s (+ 0.71%) 6.12s 6.18s p=0.030 n=6
Bind Time 2.29s (± 1.54%) 2.28s (± 0.45%) ~ 2.27s 2.30s p=0.935 n=6
Check Time 41.21s (± 0.96%) 41.12s (± 0.52%) ~ 40.92s 41.42s p=0.689 n=6
Emit Time 4.08s (± 3.88%) 4.04s (± 4.69%) ~ 3.88s 4.31s p=0.378 n=6
Total Time 53.71s (± 0.56%) 53.62s (± 0.46%) ~ 53.29s 53.95s p=0.471 n=6
self-build-src-public-api - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,250,213 1,250,582 +369 (+ 0.03%) ~ ~ p=0.001 n=6
Types 265,146 265,307 +161 (+ 0.06%) ~ ~ p=0.001 n=6
Memory used 2,478,285k (± 0.11%) 2,477,902k (± 0.02%) ~ 2,477,333k 2,478,582k p=0.298 n=6
Parse Time 5.28s (± 0.44%) 5.25s (± 0.88%) ~ 5.19s 5.31s p=0.199 n=6
Bind Time 1.70s (± 0.53%) 1.71s (± 0.88%) ~ 1.70s 1.73s p=0.156 n=6
Check Time 35.13s (± 0.36%) 35.13s (± 0.27%) ~ 34.97s 35.23s p=0.630 n=6
Emit Time 3.35s (± 1.58%) 3.40s (± 4.18%) ~ 3.32s 3.68s p=0.936 n=6
Total Time 45.46s (± 0.35%) 45.50s (± 0.47%) ~ 45.22s 45.87s p=0.575 n=6
self-compiler - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 259,449 259,701 +252 (+ 0.10%) ~ ~ p=0.001 n=6
Types 105,986 106,138 +152 (+ 0.14%) ~ ~ p=0.001 n=6
Memory used 433,843k (± 0.01%) 434,207k (± 0.02%) +365k (+ 0.08%) 434,075k 434,322k p=0.005 n=6
Parse Time 3.43s (± 0.76%) 3.43s (± 0.87%) ~ 3.39s 3.47s p=1.000 n=6
Bind Time 1.28s (± 0.40%) 1.27s (± 0.32%) -0.01s (- 0.65%) 1.26s 1.27s p=0.022 n=6
Check Time 18.16s (± 0.35%) 18.09s (± 0.22%) ~ 18.04s 18.16s p=0.166 n=6
Emit Time 1.66s (± 1.52%) 1.65s (± 0.71%) ~ 1.64s 1.67s p=0.511 n=6
Total Time 24.52s (± 0.27%) 24.44s (± 0.14%) -0.08s (- 0.34%) 24.40s 24.49s p=0.030 n=6
ts-pre-modules - node (v18.15.0, x64)
Errors 68 68 ~ ~ ~ p=1.000 n=6
Symbols 225,018 225,018 ~ ~ ~ p=1.000 n=6
Types 94,249 94,249 ~ ~ ~ p=1.000 n=6
Memory used 370,192k (± 0.02%) 370,274k (± 0.02%) ~ 370,194k 370,433k p=0.128 n=6
Parse Time 2.76s (± 1.14%) 2.77s (± 0.50%) ~ 2.76s 2.79s p=0.517 n=6
Bind Time 1.58s (± 1.41%) 1.57s (± 0.57%) ~ 1.56s 1.58s p=0.676 n=6
Check Time 15.74s (± 0.35%) 15.80s (± 0.38%) ~ 15.73s 15.90s p=0.126 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 20.08s (± 0.36%) 20.14s (± 0.27%) ~ 20.09s 20.24s p=0.148 n=6
vscode - node (v18.15.0, x64)
Errors 1 1 ~ ~ ~ p=1.000 n=6
Symbols 3,052,318 3,052,376 +58 (+ 0.00%) ~ ~ p=0.001 n=6
Types 1,055,622 1,055,643 +21 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 3,161,885k (± 0.00%) 3,161,935k (± 0.00%) ~ 3,161,880k 3,161,998k p=0.093 n=6
Parse Time 13.88s (± 0.23%) 13.91s (± 0.37%) ~ 13.85s 13.97s p=0.332 n=6
Bind Time 4.36s (± 0.24%) 4.36s (± 0.19%) ~ 4.35s 4.37s p=0.923 n=6
Check Time 81.54s (± 0.20%) 81.79s (± 0.42%) ~ 81.19s 82.14s p=0.173 n=6
Emit Time 22.20s (± 0.47%) 22.16s (± 0.39%) ~ 22.00s 22.23s p=0.810 n=6
Total Time 121.98s (± 0.21%) 122.22s (± 0.25%) ~ 121.68s 122.62s p=0.173 n=6
webpack - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 277,156 277,089 -67 (- 0.02%) ~ ~ p=0.001 n=6
Types 112,946 113,102 +156 (+ 0.14%) ~ ~ p=0.001 n=6
Memory used 426,974k (± 0.02%) 427,050k (± 0.03%) ~ 426,860k 427,189k p=0.230 n=6
Parse Time 4.91s (± 0.47%) 4.89s (± 0.27%) ~ 4.87s 4.91s p=0.164 n=6
Bind Time 2.15s (± 0.88%) 2.14s (± 1.54%) ~ 2.10s 2.19s p=0.625 n=6
Check Time 21.81s (± 0.25%) 21.78s (± 0.47%) ~ 21.66s 21.91s p=1.000 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 28.87s (± 0.18%) 28.81s (± 0.42%) ~ 28.66s 28.94s p=0.575 n=6
xstate-main - node (v18.15.0, x64)
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 539,317 539,355 +38 (+ 0.01%) ~ ~ p=0.001 n=6
Types 178,997 179,004 +7 (+ 0.00%) ~ ~ p=0.001 n=6
Memory used 484,083k (± 0.03%) 484,223k (± 0.02%) ~ 484,144k 484,376k p=0.093 n=6
Parse Time 4.26s (± 0.29%) 4.26s (± 0.61%) ~ 4.22s 4.28s p=0.869 n=6
Bind Time 1.55s (± 0.97%) 1.55s (± 0.63%) ~ 1.53s 1.56s p=0.864 n=6
Check Time 22.61s (± 0.43%) 22.85s (± 0.40%) +0.24s (+ 1.06%) 22.76s 22.98s p=0.005 n=6
Emit Time 0.00s 0.00s ~ ~ ~ p=1.000 n=6
Total Time 28.43s (± 0.37%) 28.66s (± 0.34%) +0.23s (+ 0.80%) 28.56s 28.82s p=0.012 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

@weswigham
Copy link
Member Author

There we go, no more new errors in angular - now just to see if top400 comes back cleaner, too. (I think it should, the most recent fix is squarely aimed at those errors, since they're the same cause as the ones in angular - forgetting to include the explicit prop types in the implied index signature type)

@typescript-bot
Copy link
Collaborator

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

Everything looks good!

@weswigham weswigham marked this pull request as ready for review September 16, 2024 17:01
Comment on lines +16313 to +16315
if (hasComputedStringProperty && !findIndexInfo(indexInfos, stringType)) indexInfos.push(getObjectLiteralIndexInfo(readonlyComputedStringProperty, 0, allPropertySymbols, stringType));
if (hasComputedNumberProperty && !findIndexInfo(indexInfos, numberType)) indexInfos.push(getObjectLiteralIndexInfo(readonlyComputedNumberProperty, 0, allPropertySymbols, numberType));
if (hasComputedSymbolProperty && !findIndexInfo(indexInfos, esSymbolType)) indexInfos.push(getObjectLiteralIndexInfo(readonlyComputedSymbolProperty, 0, allPropertySymbols, esSymbolType));
Copy link
Member

Choose a reason for hiding this comment

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

Are all of the findIndexInfo calls likely to cost a bunch or is indexInfos just always short?

Copy link
Member Author

@weswigham weswigham Sep 18, 2024

Choose a reason for hiding this comment

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

In practice, it's always short (there's usually just string or number indexes, if any) - in theory, a user could explicitly define hundreds of pattern literal index infos and it'd be bad, however, and you'd prefer you did the up-front work to make a map keyed on key type (if you had multiple kinds of computed names). But that's not code anyone's realistically writing.

@weswigham weswigham added the Breaking Change Would introduce errors in existing code label Sep 23, 2024
@weswigham weswigham merged commit fa0080f into microsoft:main Sep 23, 2024
32 checks passed
@pfumagalli
Copy link

Hmm... I hit a bit of a snag here. I have a class like this:

import util from 'node:util'
const inspect = util.inspect.custom

export class MyMap extends Map<MyObjectA, MyObjectB> {
  [inspect](depth: number, options: util.InspectOptions): string {
    // my fancy code for making this look pretty...
  }
  // ... and here goes all the extra stuff I want
}

Now this compiles out as a .d.ts as:

export declare class MyMap extends Map<MyObjectA, MyObjectB> {
  [x: symbol]: ((depth: number, options: util.InspectOptions) => string) 
             | (() => MapIterator<[string, string]>);
  // ... all the other niceties
}

... so far so good (maybe???) but when I try to import my map in some other project I get an error:

Property '[Symbol.toStringTag]' of type 'string' is not assignable to 'symbol' index type '((depth: number, options: InspectOptions) => string) | (() => MapIterator<[string, string]>)'. [TS2411]
    [x: symbol]: ((depth: number, options: util.InspectOptions) => string) | (() => MapIterator<[string, string]>);

Why? Because `` declares Map as follows, which is obviously incompatible:

interface Map<K, V> {
    readonly [Symbol.toStringTag]: string;
}

Maybe the typescript compiler should merge all symbol declarations and write something like:

export declare class MyMap extends Map<MyObjectA, MyObjectB> {
  [x: symbol]: string 
             | ((depth: number, options: util.InspectOptions) => string) 
             | (() => MapIterator<[string, string]>);
  // ... all the other niceties
}

I don't know what'd be the right solution in these cases.

For my code, I can simply remove that assignment const inspect = util.inspect.custom and use it directly in my code:

import util from 'node:util'

export class MyMap extends Map<MyObjectA, MyObjectB> {
  [util.inspect.custom](depth: number, options: util.InspectOptions): string {
    // my fancy code for making this look pretty...
  }
  // ... and here goes all the extra stuff I want
}

produces a more correct .d.ts as follows (which makes dependant libraries work):

import util from 'node:util';

export declare class MyMap extends Map<MyObjectA, MyObjectB> {
  [util.inspect.custom]: ((depth: number, options: util.InspectOptions) => string) 
                       | (() => MapIterator<[string, string]>);
  // ... all the other niceties
}

But I noticed that anytime I import a unique symbol (such as in the case of utils.inspect.custom) assign it locally, and use it as a key in a class, the uniqueness of the symbol is somehow lost and the whole thing collapses...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team Breaking Change Would introduce errors in existing code For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants