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

Index signatures for symbols and template literal strings #44512

Open
wants to merge 46 commits into
base: main
Choose a base branch
from

Conversation

@ahejlsberg
Copy link
Member

@ahejlsberg ahejlsberg commented Jun 8, 2021

With this PR we implement support for symbol and template literal string index signatures. We furthermore permit index signature declarations to specify union key types, provided all constituents are either string, number, symbol, or template literal types with non-generic placeholders. Some examples:

type SymbolMap<T> = {
    [key: symbol]: T;
};

type DataProps = {
    [key: `data-${string}`]: string;
};

type PropertyMap = {
    [key: string | number | symbol]: string;
};

An index signature declaration that specifies a union key type is exactly equivalent to a set of distinct index signatures for each constituent key. For example, the PropertyMap declaration above is exactly equivalent to:

type PropertyMap = {
    [key: string]: string;
    [key: number]: string;
    [key: symbol]: string;
};

Index signature declarations are not permitted to specify literal key types or generic key types. Those kinds of types can only be used with mapped types, which map literals key types to distinct properties and defer resolution of generic key types until they're instantiated with non-generic types. For example:

type Thing<T> = Record<'a' | `foo${T}` | symbol, string>;

type StringThing = Thing<string>;  // { [a: string, [x: `foo${string}`]: string, [x: symbol]: string }
type BarThing = Thing<'bar'>;  // { [a: string, foobar: string, [x: symbol]: string }

This PR supercedes #26797 which was more ambitious but had overlap between regular properties and index signatures with literal key types that is difficult to reconcile, as well as generic index signatures for which type relationships become exceedingly complex to reason about.

Fixes #1863.
Fixes #26470.
Fixes #42192.

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jun 9, 2021

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jun 9, 2021

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

Here they are:

Comparison Report - master..44512

Metric master 44512 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 343,935k (± 0.03%) 344,490k (± 0.03%) +555k (+ 0.16%) 344,205k 344,681k
Parse Time 1.79s (± 0.25%) 1.80s (± 0.45%) +0.01s (+ 0.84%) 1.79s 1.82s
Bind Time 0.84s (± 0.69%) 0.84s (± 0.84%) +0.00s (+ 0.24%) 0.83s 0.86s
Check Time 5.18s (± 0.36%) 5.21s (± 0.39%) +0.03s (+ 0.50%) 5.18s 5.27s
Emit Time 5.47s (± 0.58%) 5.48s (± 0.92%) +0.01s (+ 0.24%) 5.41s 5.64s
Total Time 13.28s (± 0.35%) 13.33s (± 0.50%) +0.05s (+ 0.41%) 13.24s 13.49s
Compiler-Unions - node (v10.16.3, x64)
Memory used 200,424k (± 0.06%) 200,606k (± 0.06%) +182k (+ 0.09%) 200,300k 200,878k
Parse Time 0.78s (± 0.77%) 0.78s (± 0.83%) +0.00s (+ 0.26%) 0.76s 0.79s
Bind Time 0.53s (± 1.44%) 0.53s (± 0.94%) +0.00s (+ 0.00%) 0.51s 0.53s
Check Time 7.55s (± 0.60%) 7.59s (± 0.45%) +0.04s (+ 0.49%) 7.47s 7.65s
Emit Time 2.27s (± 0.85%) 2.25s (± 0.90%) -0.02s (- 1.06%) 2.18s 2.27s
Total Time 11.12s (± 0.50%) 11.14s (± 0.41%) +0.02s (+ 0.14%) 11.01s 11.23s
Monaco - node (v10.16.3, x64)
Memory used 340,462k (± 0.02%) 340,644k (± 0.02%) +182k (+ 0.05%) 340,488k 340,789k
Parse Time 1.44s (± 0.79%) 1.45s (± 0.76%) +0.00s (+ 0.35%) 1.42s 1.47s
Bind Time 0.74s (± 0.70%) 0.74s (± 0.79%) -0.00s (- 0.27%) 0.73s 0.75s
Check Time 5.33s (± 0.62%) 5.33s (± 0.62%) +0.00s (+ 0.04%) 5.26s 5.42s
Emit Time 2.96s (± 1.09%) 2.97s (± 0.61%) +0.00s (+ 0.10%) 2.94s 3.01s
Total Time 10.48s (± 0.34%) 10.48s (± 0.35%) +0.01s (+ 0.06%) 10.42s 10.58s
TFS - node (v10.16.3, x64)
Memory used 304,041k (± 0.02%) 304,021k (± 0.03%) -20k (- 0.01%) 303,816k 304,233k
Parse Time 1.18s (± 0.47%) 1.18s (± 0.58%) -0.00s (- 0.17%) 1.16s 1.19s
Bind Time 0.70s (± 0.83%) 0.71s (± 0.67%) +0.00s (+ 0.57%) 0.70s 0.72s
Check Time 4.85s (± 0.46%) 4.88s (± 0.52%) +0.03s (+ 0.62%) 4.82s 4.95s
Emit Time 3.04s (± 1.03%) 3.06s (± 1.47%) +0.02s (+ 0.69%) 2.96s 3.20s
Total Time 9.76s (± 0.51%) 9.81s (± 0.29%) +0.05s (+ 0.56%) 9.77s 9.92s
material-ui - node (v10.16.3, x64)
Memory used 471,636k (± 0.02%) 473,739k (± 0.01%) +2,102k (+ 0.45%) 473,604k 473,855k
Parse Time 1.72s (± 0.27%) 1.72s (± 0.52%) +0.00s (+ 0.23%) 1.71s 1.75s
Bind Time 0.66s (± 0.87%) 0.66s (± 0.79%) +0.00s (+ 0.15%) 0.65s 0.67s
Check Time 14.22s (± 0.59%) 15.00s (± 0.28%) +0.78s (+ 5.50%) 14.90s 15.08s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.60s (± 0.51%) 17.38s (± 0.28%) +0.79s (+ 4.74%) 17.27s 17.49s
Angular - node (v12.1.0, x64)
Memory used 322,171k (± 0.02%) 322,789k (± 0.03%) +618k (+ 0.19%) 322,641k 323,017k
Parse Time 1.77s (± 0.53%) 1.78s (± 0.60%) +0.01s (+ 0.51%) 1.76s 1.80s
Bind Time 0.83s (± 0.97%) 0.83s (± 0.78%) -0.00s (- 0.00%) 0.81s 0.84s
Check Time 5.07s (± 0.41%) 5.12s (± 0.51%) +0.05s (+ 0.91%) 5.07s 5.17s
Emit Time 5.65s (± 0.63%) 5.67s (± 0.48%) +0.02s (+ 0.34%) 5.62s 5.73s
Total Time 13.32s (± 0.38%) 13.40s (± 0.38%) +0.07s (+ 0.54%) 13.31s 13.52s
Compiler-Unions - node (v12.1.0, x64)
Memory used 187,842k (± 0.07%) 187,903k (± 0.15%) +61k (+ 0.03%) 187,008k 188,228k
Parse Time 0.77s (± 0.61%) 0.78s (± 0.77%) +0.01s (+ 0.65%) 0.76s 0.79s
Bind Time 0.53s (± 1.13%) 0.53s (± 1.17%) +0.00s (+ 0.57%) 0.52s 0.54s
Check Time 7.00s (± 0.51%) 7.10s (± 0.60%) +0.10s (+ 1.39%) 7.01s 7.23s
Emit Time 2.23s (± 0.58%) 2.25s (± 1.05%) +0.02s (+ 0.72%) 2.20s 2.31s
Total Time 10.52s (± 0.37%) 10.65s (± 0.53%) +0.13s (+ 1.19%) 10.54s 10.83s
Monaco - node (v12.1.0, x64)
Memory used 323,452k (± 0.02%) 323,595k (± 0.02%) +143k (+ 0.04%) 323,488k 323,732k
Parse Time 1.41s (± 0.54%) 1.42s (± 0.74%) +0.00s (+ 0.21%) 1.40s 1.45s
Bind Time 0.72s (± 0.93%) 0.71s (± 0.42%) -0.01s (- 1.26%) 0.70s 0.71s
Check Time 5.20s (± 0.47%) 5.20s (± 0.42%) 0.00s ( 0.00%) 5.16s 5.24s
Emit Time 2.99s (± 0.43%) 3.02s (± 0.56%) +0.03s (+ 1.00%) 2.98s 3.06s
Total Time 10.33s (± 0.32%) 10.35s (± 0.40%) +0.02s (+ 0.20%) 10.26s 10.47s
TFS - node (v12.1.0, x64)
Memory used 288,599k (± 0.02%) 288,519k (± 0.02%) -80k (- 0.03%) 288,389k 288,745k
Parse Time 1.18s (± 0.69%) 1.19s (± 0.71%) +0.01s (+ 0.51%) 1.17s 1.21s
Bind Time 0.70s (± 2.30%) 0.70s (± 1.41%) -0.00s (- 0.14%) 0.68s 0.73s
Check Time 4.78s (± 0.48%) 4.76s (± 0.39%) -0.02s (- 0.40%) 4.74s 4.81s
Emit Time 3.12s (± 0.59%) 3.11s (± 0.67%) -0.01s (- 0.26%) 3.05s 3.16s
Total Time 9.78s (± 0.46%) 9.76s (± 0.37%) -0.03s (- 0.27%) 9.68s 9.85s
material-ui - node (v12.1.0, x64)
Memory used 450,177k (± 0.06%) 452,460k (± 0.01%) +2,283k (+ 0.51%) 452,338k 452,637k
Parse Time 1.71s (± 0.23%) 1.71s (± 0.43%) +0.00s (+ 0.06%) 1.69s 1.72s
Bind Time 0.63s (± 0.57%) 0.64s (± 0.75%) +0.00s (+ 0.47%) 0.63s 0.65s
Check Time 12.74s (± 0.53%) 13.48s (± 0.35%) +0.73s (+ 5.76%) 13.41s 13.62s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.09s (± 0.48%) 15.83s (± 0.30%) +0.74s (+ 4.88%) 15.77s 15.98s
Angular - node (v14.15.1, x64)
Memory used 320,917k (± 0.01%) 321,345k (± 0.01%) +427k (+ 0.13%) 321,286k 321,411k
Parse Time 1.78s (± 0.26%) 1.80s (± 0.77%) +0.02s (+ 0.90%) 1.77s 1.83s
Bind Time 0.87s (± 0.57%) 0.87s (± 0.71%) +0.01s (+ 0.58%) 0.86s 0.89s
Check Time 5.08s (± 0.27%) 5.15s (± 0.57%) +0.07s (+ 1.40%) 5.08s 5.22s
Emit Time 5.71s (± 0.58%) 5.71s (± 0.45%) -0.00s (- 0.02%) 5.63s 5.75s
Total Time 13.43s (± 0.32%) 13.52s (± 0.37%) +0.09s (+ 0.66%) 13.37s 13.58s
Compiler-Unions - node (v14.15.1, x64)
Memory used 188,442k (± 0.67%) 188,133k (± 0.62%) -310k (- 0.16%) 186,777k 190,149k
Parse Time 0.80s (± 0.37%) 0.80s (± 0.74%) +0.00s (+ 0.37%) 0.79s 0.82s
Bind Time 0.55s (± 0.66%) 0.55s (± 0.66%) +0.00s (+ 0.00%) 0.55s 0.56s
Check Time 7.14s (± 0.59%) 7.20s (± 0.59%) +0.06s (+ 0.90%) 7.14s 7.35s
Emit Time 2.26s (± 1.27%) 2.26s (± 0.70%) -0.01s (- 0.27%) 2.22s 2.29s
Total Time 10.76s (± 0.51%) 10.82s (± 0.48%) +0.06s (+ 0.57%) 10.71s 10.99s
Monaco - node (v14.15.1, x64)
Memory used 322,517k (± 0.01%) 322,638k (± 0.00%) +122k (+ 0.04%) 322,601k 322,665k
Parse Time 1.46s (± 0.51%) 1.48s (± 0.46%) +0.01s (+ 0.82%) 1.45s 1.48s
Bind Time 0.74s (± 0.46%) 0.74s (± 0.78%) 0.00s ( 0.00%) 0.73s 0.76s
Check Time 5.17s (± 0.23%) 5.18s (± 0.49%) +0.01s (+ 0.19%) 5.12s 5.24s
Emit Time 3.07s (± 0.58%) 3.08s (± 0.77%) +0.01s (+ 0.46%) 3.02s 3.12s
Total Time 10.45s (± 0.26%) 10.48s (± 0.42%) +0.03s (+ 0.30%) 10.36s 10.60s
TFS - node (v14.15.1, x64)
Memory used 287,631k (± 0.00%) 287,603k (± 0.01%) -28k (- 0.01%) 287,539k 287,651k
Parse Time 1.24s (± 0.97%) 1.25s (± 1.23%) +0.01s (+ 0.48%) 1.22s 1.28s
Bind Time 0.71s (± 0.87%) 0.71s (± 1.06%) +0.00s (+ 0.42%) 0.70s 0.74s
Check Time 4.80s (± 0.40%) 4.79s (± 0.33%) -0.01s (- 0.17%) 4.76s 4.83s
Emit Time 3.23s (± 1.03%) 3.21s (± 0.65%) -0.02s (- 0.71%) 3.16s 3.25s
Total Time 9.99s (± 0.43%) 9.96s (± 0.35%) -0.03s (- 0.27%) 9.88s 10.04s
material-ui - node (v14.15.1, x64)
Memory used 448,641k (± 0.00%) 450,743k (± 0.01%) +2,102k (+ 0.47%) 450,656k 450,824k
Parse Time 1.74s (± 0.42%) 1.75s (± 0.79%) +0.01s (+ 0.52%) 1.72s 1.79s
Bind Time 0.69s (± 0.58%) 0.69s (± 0.48%) -0.00s (- 0.14%) 0.68s 0.70s
Check Time 12.93s (± 0.62%) 13.66s (± 0.54%) +0.74s (+ 5.70%) 13.54s 13.79s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.36s (± 0.54%) 16.10s (± 0.50%) +0.75s (+ 4.85%) 15.97s 16.27s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory1 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
Benchmark Name Iterations
Current 44512 10
Baseline master 10

Developer Information:

Download Benchmark

Copy link
Member

@weswigham weswigham left a comment

Shouldn't we allow any and never as index signature key types as well? They're both non-generic intrinsics assignable to string | number | symbol, so I don't see why not. any is essentially just a short string | number | symbol, while never would be an index signature that either

  • Doesn't actually exist and is immediately removed (which... isn't too useful?), or
  • Is an index signature that only handles never lookups, eg {[idx: never]: never; [idx: string]: string}[never] would be never and not string (which probably has use for defining error fallbacks for lookup types).
// When more than one index signature is applicable we create a synthetic IndexInfo. Instead of computing
// the intersected key type, we just use unknownType for the key type as nothing actually depends on the
// keyType property of the returned IndexInfo.
return applicableInfos ? createIndexInfo(unknownType, getIntersectionType(map(applicableInfos, info => info.type)),

This comment has been minimized.

@weswigham

weswigham Jun 9, 2021
Member

unknown isn't assignable to string | number | symbol - maybe it'd be better to use any here on the offchance it leaks somewhere in the future?

This comment has been minimized.

@ahejlsberg

ahejlsberg Jun 9, 2021
Author Member

To ensure property round-tripping, our guiding principle should be what happens when you feed a particular type through a mapped type. Currently, feeding an any through a mapped type produces a string index signature. That used to make sense because it was the widest possible index signature, but you could argue we should equate any to string | number | symbol and have it be shorthand for all three index signatures. That may or may not affect existing code, but we could try.

This comment has been minimized.

@ahejlsberg

ahejlsberg Jun 9, 2021
Author Member

Oops, comment above was meant for your general question about any and never.

This comment has been minimized.

@ahejlsberg

ahejlsberg Jun 9, 2021
Author Member

Meanwhile, sure it might be better to use any for the key type for synthetic index infos.

This comment has been minimized.

@weswigham

weswigham Jun 9, 2021
Member

but you could argue we should equate any to string | number | symbol and have it be shorthand for all three index signatures. That may or may not affect existing code, but we could try.

Yeah, it makes sense, imo, for a mapped type over any to make an any index signature, since that'll actually handle symbols. (Just like the any input could have)

// signature applies to types assignable to 'number' and numeric string literal types.
return isTypeAssignableTo(source, target) ||
target === stringType && isTypeAssignableTo(source, numberType) ||
target === numberType && source.flags & TypeFlags.StringLiteral && isNumericLiteralName((source as StringLiteralType).value);

This comment has been minimized.

@weswigham

weswigham Jun 9, 2021
Member

There's also the type

type NumericStrings = `${number}`

which might warrant special-casing here, as well? It's a bit awkward because "0.0" is a "numeric string" but is actually a distinct object key string from "0"; but that's already true for the literals themselves, so.... ¯\(ツ)

This comment has been minimized.

@ahejlsberg

ahejlsberg Jun 9, 2021
Author Member

I'm not sure there's any meaningful special casing we could do for `${number}` because, as you already point out, it may or may not contain a round-trippable numeric string.

if (someType(type, t => !!(t.flags & (TypeFlags.StringOrNumberLiteralOrUnique | TypeFlags.Instantiable)) && !isPatternLiteralType(t))) {
return grammarErrorOnNode(parameter.name, Diagnostics.An_index_signature_parameter_type_cannot_be_a_literal_type_or_generic_type_Consider_using_a_mapped_object_type_instead);
}
if (!everyType(type, t => !!(t.flags & (TypeFlags.String | TypeFlags.Number | TypeFlags.ESSymbol | TypeFlags.TemplateLiteral)))) {

This comment has been minimized.

@weswigham

weswigham Jun 9, 2021
Member

TypeFlags.StringMapping?

This comment has been minimized.

@ahejlsberg

ahejlsberg Jun 9, 2021
Author Member

Nope, TypeFlags.StringMapping is an instantiable type and it was already barred by the test above.

This comment has been minimized.

@weswigham

weswigham Jun 9, 2021
Member

Hm, on inspection,

type A = Uppercase<`${number}`>;

Is just

type A = `${number}`;

so they just evaporate around patterns (after affecting the concrete bits, even though, conceptually, they should represent a different, smaller, set of strings in the holes), so I guess we don't need to handle them right now. But if we ever change up mappings over/in patterns to be preserved, we'll need to change this to match, I guess.

This comment has been minimized.

@ahejlsberg

ahejlsberg Jun 10, 2021
Author Member

Yeah, we're good there for now. However, it does appear we don't properly apply the string mapping to template literal types with non-generic patterns. For example, Uppercase<`foo${string}bar`> should become `FOO${string}BAR`, but simply resolves to `foo${string}bar` now. It's unrelated to this PR, but something we should fix.

@DanielRosenwasser
Copy link
Member

@DanielRosenwasser DanielRosenwasser commented Jun 9, 2021

Shouldn't we allow any and never as index signature key types as well?

My understanding from the last design meeting was that we were limiting the new types of index signatures to match the biggest use-cases that we had, keeping room to generalize for unions, finite types, any, unknown, never, and enum types.

With that in mind, I'm actually surprised to see unions supported in index signatures in this PR.

@ahejlsberg
Copy link
Member Author

@ahejlsberg ahejlsberg commented Jun 9, 2021

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jun 9, 2021

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

Update: The results are in!

@ahejlsberg
Copy link
Member Author

@ahejlsberg ahejlsberg commented Jun 9, 2021

I'm actually surprised to see unions supported in index signatures in this PR.

Unions per se are not the problem as they can trivially be expanded to individual index signatures for each constituent. (Might as well have the convenience of writing [key: string | number | symbol]: xxx instead of requiring three distinct declarations.) The trouble comes from (unions of) literal types and generic types as they do not become index signatures when fed through mapped types. Those are the ones we need to prohibit.

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jun 9, 2021

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

Here they are:

Comparison Report - master..44512

Metric master 44512 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 343,935k (± 0.03%) 344,476k (± 0.02%) +540k (+ 0.16%) 344,344k 344,628k
Parse Time 1.79s (± 0.25%) 1.81s (± 0.77%) +0.02s (+ 1.17%) 1.78s 1.84s
Bind Time 0.84s (± 0.69%) 0.84s (± 0.70%) +0.01s (+ 0.84%) 0.83s 0.86s
Check Time 5.18s (± 0.36%) 5.21s (± 0.56%) +0.03s (+ 0.60%) 5.16s 5.27s
Emit Time 5.47s (± 0.58%) 5.52s (± 0.35%) +0.05s (+ 0.86%) 5.48s 5.56s
Total Time 13.28s (± 0.35%) 13.38s (± 0.36%) +0.10s (+ 0.75%) 13.30s 13.49s
Compiler-Unions - node (v10.16.3, x64)
Memory used 200,424k (± 0.06%) 200,684k (± 0.03%) +260k (+ 0.13%) 200,580k 200,788k
Parse Time 0.78s (± 0.77%) 0.78s (± 0.63%) 0.00s ( 0.00%) 0.77s 0.79s
Bind Time 0.53s (± 1.44%) 0.53s (± 1.05%) +0.00s (+ 0.38%) 0.51s 0.54s
Check Time 7.55s (± 0.60%) 7.54s (± 0.30%) -0.01s (- 0.11%) 7.50s 7.58s
Emit Time 2.27s (± 0.85%) 2.23s (± 0.79%) -0.04s (- 1.85%) 2.19s 2.27s
Total Time 11.12s (± 0.50%) 11.07s (± 0.32%) -0.05s (- 0.41%) 11.00s 11.13s
Monaco - node (v10.16.3, x64)
Memory used 340,462k (± 0.02%) 340,634k (± 0.02%) +172k (+ 0.05%) 340,491k 340,756k
Parse Time 1.44s (± 0.79%) 1.45s (± 0.40%) +0.01s (+ 0.76%) 1.44s 1.47s
Bind Time 0.74s (± 0.70%) 0.74s (± 0.67%) -0.00s (- 0.41%) 0.73s 0.75s
Check Time 5.33s (± 0.62%) 5.35s (± 0.56%) +0.02s (+ 0.28%) 5.29s 5.42s
Emit Time 2.96s (± 1.09%) 2.96s (± 0.54%) -0.00s (- 0.03%) 2.93s 3.00s
Total Time 10.48s (± 0.34%) 10.50s (± 0.25%) +0.02s (+ 0.21%) 10.44s 10.55s
TFS - node (v10.16.3, x64)
Memory used 304,041k (± 0.02%) 303,929k (± 0.02%) -112k (- 0.04%) 303,844k 304,159k
Parse Time 1.18s (± 0.47%) 1.18s (± 0.34%) +0.00s (+ 0.08%) 1.17s 1.19s
Bind Time 0.70s (± 0.83%) 0.70s (± 0.70%) +0.00s (+ 0.14%) 0.69s 0.71s
Check Time 4.85s (± 0.46%) 4.86s (± 0.31%) +0.02s (+ 0.35%) 4.83s 4.90s
Emit Time 3.04s (± 1.03%) 3.04s (± 1.67%) +0.01s (+ 0.26%) 2.94s 3.13s
Total Time 9.76s (± 0.51%) 9.79s (± 0.65%) +0.03s (+ 0.32%) 9.68s 9.89s
material-ui - node (v10.16.3, x64)
Memory used 471,636k (± 0.02%) 473,614k (± 0.01%) +1,978k (+ 0.42%) 473,507k 473,721k
Parse Time 1.72s (± 0.27%) 1.73s (± 0.34%) +0.01s (+ 0.35%) 1.71s 1.74s
Bind Time 0.66s (± 0.87%) 0.66s (± 0.68%) -0.00s (- 0.30%) 0.65s 0.67s
Check Time 14.22s (± 0.59%) 14.96s (± 0.55%) +0.75s (+ 5.26%) 14.84s 15.17s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.60s (± 0.51%) 17.35s (± 0.48%) +0.76s (+ 4.55%) 17.23s 17.58s
Angular - node (v12.1.0, x64)
Memory used 322,171k (± 0.02%) 322,578k (± 0.04%) +406k (+ 0.13%) 322,349k 322,894k
Parse Time 1.77s (± 0.53%) 1.78s (± 0.77%) +0.01s (+ 0.56%) 1.75s 1.82s
Bind Time 0.83s (± 0.97%) 0.83s (± 0.67%) -0.00s (- 0.00%) 0.82s 0.84s
Check Time 5.07s (± 0.41%) 5.11s (± 0.33%) +0.04s (+ 0.89%) 5.07s 5.16s
Emit Time 5.65s (± 0.63%) 5.66s (± 0.43%) +0.00s (+ 0.04%) 5.60s 5.71s
Total Time 13.32s (± 0.38%) 13.38s (± 0.21%) +0.06s (+ 0.42%) 13.33s 13.46s
Compiler-Unions - node (v12.1.0, x64)
Memory used 187,842k (± 0.07%) 187,983k (± 0.13%) +141k (+ 0.08%) 187,088k 188,243k
Parse Time 0.77s (± 0.61%) 0.77s (± 0.87%) -0.00s (- 0.39%) 0.75s 0.78s
Bind Time 0.53s (± 1.13%) 0.53s (± 0.98%) +0.00s (+ 0.95%) 0.52s 0.54s
Check Time 7.00s (± 0.51%) 7.03s (± 0.51%) +0.03s (+ 0.36%) 6.97s 7.11s
Emit Time 2.23s (± 0.58%) 2.25s (± 1.06%) +0.02s (+ 0.94%) 2.22s 2.32s
Total Time 10.52s (± 0.37%) 10.57s (± 0.41%) +0.05s (+ 0.44%) 10.47s 10.66s
Monaco - node (v12.1.0, x64)
Memory used 323,452k (± 0.02%) 323,673k (± 0.02%) +221k (+ 0.07%) 323,585k 323,798k
Parse Time 1.41s (± 0.54%) 1.42s (± 0.83%) +0.01s (+ 0.35%) 1.40s 1.45s
Bind Time 0.72s (± 0.93%) 0.71s (± 0.67%) -0.00s (- 0.56%) 0.71s 0.73s
Check Time 5.20s (± 0.47%) 5.18s (± 0.44%) -0.02s (- 0.40%) 5.13s 5.25s
Emit Time 2.99s (± 0.43%) 3.00s (± 0.59%) +0.01s (+ 0.37%) 2.96s 3.05s
Total Time 10.33s (± 0.32%) 10.31s (± 0.36%) -0.01s (- 0.13%) 10.22s 10.41s
TFS - node (v12.1.0, x64)
Memory used 288,599k (± 0.02%) 288,583k (± 0.02%) -17k (- 0.01%) 288,422k 288,698k
Parse Time 1.18s (± 0.69%) 1.19s (± 0.61%) +0.01s (+ 0.42%) 1.18s 1.21s
Bind Time 0.70s (± 2.30%) 0.68s (± 1.21%) -0.01s (- 2.00%) 0.67s 0.71s
Check Time 4.78s (± 0.48%) 4.76s (± 0.68%) -0.02s (- 0.52%) 4.70s 4.82s
Emit Time 3.12s (± 0.59%) 3.12s (± 0.51%) -0.00s (- 0.03%) 3.08s 3.14s
Total Time 9.78s (± 0.46%) 9.75s (± 0.40%) -0.04s (- 0.37%) 9.67s 9.82s
material-ui - node (v12.1.0, x64)
Memory used 450,177k (± 0.06%) 452,255k (± 0.06%) +2,078k (+ 0.46%) 451,159k 452,462k
Parse Time 1.71s (± 0.23%) 1.71s (± 0.34%) -0.00s (- 0.23%) 1.69s 1.72s
Bind Time 0.63s (± 0.57%) 0.64s (± 0.75%) +0.00s (+ 0.47%) 0.63s 0.65s
Check Time 12.74s (± 0.53%) 13.41s (± 0.84%) +0.67s (+ 5.27%) 13.26s 13.70s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.09s (± 0.48%) 15.76s (± 0.72%) +0.67s (+ 4.43%) 15.60s 16.04s
Angular - node (v14.15.1, x64)
Memory used 320,917k (± 0.01%) 321,345k (± 0.01%) +427k (+ 0.13%) 321,293k 321,414k
Parse Time 1.78s (± 0.26%) 1.78s (± 0.37%) +0.00s (+ 0.17%) 1.77s 1.80s
Bind Time 0.87s (± 0.57%) 0.87s (± 0.39%) +0.01s (+ 0.81%) 0.87s 0.88s
Check Time 5.08s (± 0.27%) 5.13s (± 0.54%) +0.05s (+ 0.99%) 5.08s 5.20s
Emit Time 5.71s (± 0.58%) 5.70s (± 0.68%) -0.01s (- 0.09%) 5.64s 5.83s
Total Time 13.43s (± 0.32%) 13.48s (± 0.46%) +0.05s (+ 0.39%) 13.37s 13.65s
Compiler-Unions - node (v14.15.1, x64)
Memory used 188,442k (± 0.67%) 189,656k (± 0.37%) +1,214k (+ 0.64%) 186,973k 190,108k
Parse Time 0.80s (± 0.37%) 0.80s (± 0.59%) +0.00s (+ 0.12%) 0.79s 0.81s
Bind Time 0.55s (± 0.66%) 0.56s (± 0.89%) +0.00s (+ 0.36%) 0.55s 0.57s
Check Time 7.14s (± 0.59%) 7.14s (± 0.53%) +0.00s (+ 0.04%) 7.08s 7.24s
Emit Time 2.26s (± 1.27%) 2.26s (± 1.38%) -0.00s (- 0.13%) 2.21s 2.35s
Total Time 10.76s (± 0.51%) 10.77s (± 0.51%) +0.00s (+ 0.04%) 10.67s 10.90s
Monaco - node (v14.15.1, x64)
Memory used 322,517k (± 0.01%) 322,641k (± 0.01%) +124k (+ 0.04%) 322,583k 322,697k
Parse Time 1.46s (± 0.51%) 1.47s (± 0.71%) +0.00s (+ 0.34%) 1.45s 1.49s
Bind Time 0.74s (± 0.46%) 0.74s (± 0.60%) -0.00s (- 0.13%) 0.73s 0.75s
Check Time 5.17s (± 0.23%) 5.17s (± 0.59%) -0.01s (- 0.17%) 5.13s 5.25s
Emit Time 3.07s (± 0.58%) 3.06s (± 0.71%) -0.00s (- 0.10%) 3.01s 3.13s
Total Time 10.45s (± 0.26%) 10.44s (± 0.36%) -0.01s (- 0.11%) 10.34s 10.52s
TFS - node (v14.15.1, x64)
Memory used 287,631k (± 0.00%) 287,602k (± 0.00%) -29k (- 0.01%) 287,574k 287,621k
Parse Time 1.24s (± 0.97%) 1.24s (± 1.34%) +0.00s (+ 0.00%) 1.22s 1.30s
Bind Time 0.71s (± 0.87%) 0.71s (± 0.69%) +0.00s (+ 0.42%) 0.70s 0.72s
Check Time 4.80s (± 0.40%) 4.81s (± 0.65%) +0.01s (+ 0.12%) 4.73s 4.87s
Emit Time 3.23s (± 1.03%) 3.23s (± 0.65%) -0.00s (- 0.03%) 3.19s 3.28s
Total Time 9.99s (± 0.43%) 9.99s (± 0.49%) +0.01s (+ 0.05%) 9.92s 10.14s
material-ui - node (v14.15.1, x64)
Memory used 448,641k (± 0.00%) 450,612k (± 0.00%) +1,971k (+ 0.44%) 450,566k 450,647k
Parse Time 1.74s (± 0.42%) 1.74s (± 0.51%) -0.00s (- 0.06%) 1.73s 1.76s
Bind Time 0.69s (± 0.58%) 0.69s (± 0.50%) -0.00s (- 0.58%) 0.68s 0.69s
Check Time 12.93s (± 0.62%) 13.54s (± 0.47%) +0.62s (+ 4.77%) 13.42s 13.71s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.36s (± 0.54%) 15.97s (± 0.37%) +0.61s (+ 3.99%) 15.84s 16.12s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory1 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
Benchmark Name Iterations
Current 44512 10
Baseline master 10

Developer Information:

Download Benchmark

const x1 = combo['foo-test']; // 'a' | 'b'
const x2 = combo['test-bar']; // 'b' | 'c'
const x3 = combo['foo-test-bar']; // 'b' (('a' | 'b') & ('b' | 'c'))

This comment has been minimized.

@weswigham

weswigham Jun 9, 2021
Member

Can we also add a test for

declare var str: string;
const x4 = combo[`foo-${str}-bar`];
const x5 = combo[`${str}-bar`];
const x6 = combo[`foo-${str}`];

? Mostly because element access locations aren't literal locations, per sey, in main right now (and that was a change I had to make in my PR).

// When more than one index signature is applicable we create a synthetic IndexInfo. Instead of computing
// the intersected key type, we just use unknownType for the key type as nothing actually depends on the
// keyType property of the returned IndexInfo.
return applicableInfos ? createIndexInfo(unknownType, getIntersectionType(map(applicableInfos, info => info.type)),

This comment has been minimized.

@weswigham

weswigham Jun 9, 2021
Member

Oh, one other LS-related question this reminds me of (since the composite doesn't preserve declarations in the index info) - when you have

type A = {[idx: `foo${string}`]: {x: any}} & {[idx: `${string}bar`]: {y: any}}
declare var x: A;
const q1 = x.foobar/**/;

and you go-to-def on foobar, do we return both index signatures as the definition locations (as I think we should)?

@andrewbranch
Copy link
Member

@andrewbranch andrewbranch commented Jun 9, 2021

@typescript-bot pack this

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jun 9, 2021

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

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jun 9, 2021

Hey @andrewbranch, 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/104791/artifacts?artifactName=tgz&fileId=4527B3BDAAD928FA1F795E61980CA1CA4F20D6E20207C20291C5F1587418E77402&fileName=/typescript-4.4.0-insiders.20210609.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@4.4.0-pr-44512-17".;

@DanielRosenwasser
Copy link
Member

@DanielRosenwasser DanielRosenwasser commented Jun 9, 2021

One thing that's odd is

type Foo = {
    [x: string | number]: string;
}

desugars to

type Foo = {
    [x: string]: string;
    [x: number]: string;
}

even though that's functionally the same as

type Foo = {
    [x: string]: string;
}

right?

@ahejlsberg
Copy link
Member Author

@ahejlsberg ahejlsberg commented Jun 9, 2021

@DanielRosenwasser Yes, that is a bit odd, but it's consistent with what happens if you feed string | number through a mapped type. For example, Record<string | number, string> produces a type with both index signatures.

@ahejlsberg
Copy link
Member Author

@ahejlsberg ahejlsberg commented Jun 10, 2021

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jun 10, 2021

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jun 10, 2021

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

Here they are:

Comparison Report - master..44512

Metric master 44512 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 343,935k (± 0.03%) 344,474k (± 0.02%) +538k (+ 0.16%) 344,286k 344,672k
Parse Time 1.79s (± 0.25%) 1.80s (± 0.39%) +0.01s (+ 0.73%) 1.79s 1.82s
Bind Time 0.84s (± 0.69%) 0.84s (± 0.69%) 0.00s ( 0.00%) 0.83s 0.85s
Check Time 5.18s (± 0.36%) 5.20s (± 0.33%) +0.02s (+ 0.41%) 5.16s 5.23s
Emit Time 5.47s (± 0.58%) 5.48s (± 0.68%) +0.01s (+ 0.20%) 5.41s 5.59s
Total Time 13.28s (± 0.35%) 13.32s (± 0.27%) +0.04s (+ 0.32%) 13.26s 13.41s
Compiler-Unions - node (v10.16.3, x64)
Memory used 200,424k (± 0.06%) 200,657k (± 0.05%) +233k (+ 0.12%) 200,476k 200,853k
Parse Time 0.78s (± 0.77%) 0.78s (± 0.75%) +0.00s (+ 0.13%) 0.77s 0.79s
Bind Time 0.53s (± 1.44%) 0.53s (± 1.25%) +0.00s (+ 0.76%) 0.51s 0.54s
Check Time 7.55s (± 0.60%) 7.54s (± 0.88%) -0.00s (- 0.07%) 7.41s 7.73s
Emit Time 2.27s (± 0.85%) 2.23s (± 0.79%) -0.04s (- 1.76%) 2.19s 2.27s
Total Time 11.12s (± 0.50%) 11.08s (± 0.66%) -0.04s (- 0.34%) 10.94s 11.29s
Monaco - node (v10.16.3, x64)
Memory used 340,462k (± 0.02%) 340,683k (± 0.02%) +221k (+ 0.06%) 340,582k 340,843k
Parse Time 1.44s (± 0.79%) 1.44s (± 0.41%) +0.00s (+ 0.21%) 1.43s 1.46s
Bind Time 0.74s (± 0.70%) 0.74s (± 0.88%) -0.00s (- 0.14%) 0.73s 0.76s
Check Time 5.33s (± 0.62%) 5.35s (± 0.48%) +0.02s (+ 0.34%) 5.29s 5.41s
Emit Time 2.96s (± 1.09%) 2.95s (± 0.81%) -0.01s (- 0.44%) 2.90s 2.99s
Total Time 10.48s (± 0.34%) 10.49s (± 0.44%) +0.01s (+ 0.09%) 10.40s 10.61s
TFS - node (v10.16.3, x64)
Memory used 304,041k (± 0.02%) 303,984k (± 0.01%) -57k (- 0.02%) 303,868k 304,056k
Parse Time 1.18s (± 0.47%) 1.18s (± 0.76%) -0.00s (- 0.25%) 1.16s 1.20s
Bind Time 0.70s (± 0.83%) 0.71s (± 0.95%) +0.00s (+ 0.57%) 0.69s 0.72s
Check Time 4.85s (± 0.46%) 4.87s (± 0.58%) +0.02s (+ 0.39%) 4.81s 4.94s
Emit Time 3.04s (± 1.03%) 3.07s (± 1.73%) +0.03s (+ 0.99%) 2.98s 3.19s
Total Time 9.76s (± 0.51%) 9.81s (± 0.73%) +0.05s (+ 0.54%) 9.66s 10.01s
material-ui - node (v10.16.3, x64)
Memory used 471,636k (± 0.02%) 473,517k (± 0.01%) +1,881k (+ 0.40%) 473,382k 473,674k
Parse Time 1.72s (± 0.27%) 1.72s (± 0.40%) -0.00s (- 0.29%) 1.70s 1.73s
Bind Time 0.66s (± 0.87%) 0.66s (± 0.98%) +0.00s (+ 0.30%) 0.65s 0.68s
Check Time 14.22s (± 0.59%) 14.91s (± 0.44%) +0.70s (+ 4.92%) 14.83s 15.14s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.60s (± 0.51%) 17.29s (± 0.42%) +0.70s (+ 4.19%) 17.20s 17.53s
Angular - node (v12.1.0, x64)
Memory used 322,171k (± 0.02%) 322,502k (± 0.09%) +330k (+ 0.10%) 321,419k 322,766k
Parse Time 1.77s (± 0.53%) 1.77s (± 0.58%) -0.00s (- 0.06%) 1.75s 1.80s
Bind Time 0.83s (± 0.97%) 0.82s (± 0.63%) -0.01s (- 0.85%) 0.81s 0.83s
Check Time 5.07s (± 0.41%) 5.09s (± 0.51%) +0.03s (+ 0.49%) 5.04s 5.16s
Emit Time 5.65s (± 0.63%) 5.69s (± 0.72%) +0.03s (+ 0.53%) 5.62s 5.82s
Total Time 13.32s (± 0.38%) 13.37s (± 0.44%) +0.05s (+ 0.37%) 13.24s 13.55s
Compiler-Unions - node (v12.1.0, x64)
Memory used 187,842k (± 0.07%) 188,122k (± 0.07%) +280k (+ 0.15%) 187,657k 188,262k
Parse Time 0.77s (± 0.61%) 0.76s (± 0.76%) -0.01s (- 0.91%) 0.75s 0.78s
Bind Time 0.53s (± 1.13%) 0.53s (± 0.56%) +0.00s (+ 0.38%) 0.52s 0.53s
Check Time 7.00s (± 0.51%) 7.00s (± 0.52%) 0.00s ( 0.00%) 6.94s 7.09s
Emit Time 2.23s (± 0.58%) 2.26s (± 1.13%) +0.03s (+ 1.17%) 2.21s 2.32s
Total Time 10.52s (± 0.37%) 10.55s (± 0.51%) +0.03s (+ 0.28%) 10.46s 10.68s
Monaco - node (v12.1.0, x64)
Memory used 323,452k (± 0.02%) 323,628k (± 0.01%) +176k (+ 0.05%) 323,546k 323,751k
Parse Time 1.41s (± 0.54%) 1.41s (± 0.81%) -0.00s (- 0.14%) 1.39s 1.44s
Bind Time 0.72s (± 0.93%) 0.71s (± 0.52%) -0.00s (- 0.28%) 0.71s 0.72s
Check Time 5.20s (± 0.47%) 5.19s (± 0.44%) -0.01s (- 0.17%) 5.16s 5.27s
Emit Time 2.99s (± 0.43%) 3.01s (± 0.62%) +0.02s (+ 0.50%) 2.96s 3.05s
Total Time 10.33s (± 0.32%) 10.32s (± 0.40%) -0.00s (- 0.03%) 10.25s 10.43s
TFS - node (v12.1.0, x64)
Memory used 288,599k (± 0.02%) 288,525k (± 0.02%) -74k (- 0.03%) 288,405k 288,623k
Parse Time 1.18s (± 0.69%) 1.18s (± 0.57%) +0.00s (+ 0.08%) 1.17s 1.20s
Bind Time 0.70s (± 2.30%) 0.68s (± 0.53%) -0.02s (- 2.15%) 0.68s 0.69s
Check Time 4.78s (± 0.48%) 4.77s (± 0.59%) -0.02s (- 0.31%) 4.72s 4.86s
Emit Time 3.12s (± 0.59%) 3.12s (± 0.70%) +0.00s (+ 0.00%) 3.05s 3.16s
Total Time 9.78s (± 0.46%) 9.75s (± 0.41%) -0.03s (- 0.32%) 9.66s 9.85s
material-ui - node (v12.1.0, x64)
Memory used 450,177k (± 0.06%) 452,332k (± 0.02%) +2,155k (+ 0.48%) 452,146k 452,478k
Parse Time 1.71s (± 0.23%) 1.71s (± 0.61%) -0.00s (- 0.18%) 1.69s 1.73s
Bind Time 0.63s (± 0.57%) 0.64s (± 0.93%) +0.00s (+ 0.32%) 0.63s 0.65s
Check Time 12.74s (± 0.53%) 13.38s (± 0.37%) +0.64s (+ 5.03%) 13.30s 13.52s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.09s (± 0.48%) 15.73s (± 0.32%) +0.64s (+ 4.24%) 15.65s 15.88s
Angular - node (v14.15.1, x64)
Memory used 320,917k (± 0.01%) 321,338k (± 0.00%) +421k (+ 0.13%) 321,317k 321,377k
Parse Time 1.78s (± 0.26%) 1.79s (± 0.56%) +0.01s (+ 0.56%) 1.77s 1.81s
Bind Time 0.87s (± 0.57%) 0.88s (± 0.78%) +0.01s (+ 1.15%) 0.86s 0.89s
Check Time 5.08s (± 0.27%) 5.13s (± 0.57%) +0.05s (+ 1.04%) 5.09s 5.23s
Emit Time 5.71s (± 0.58%) 5.71s (± 0.64%) -0.00s (- 0.04%) 5.66s 5.82s
Total Time 13.43s (± 0.32%) 13.50s (± 0.48%) +0.07s (+ 0.52%) 13.43s 13.69s
Compiler-Unions - node (v14.15.1, x64)
Memory used 188,442k (± 0.67%) 189,444k (± 0.51%) +1,002k (+ 0.53%) 186,852k 190,162k
Parse Time 0.80s (± 0.37%) 0.81s (± 0.82%) +0.01s (+ 1.00%) 0.80s 0.82s
Bind Time 0.55s (± 0.66%) 0.55s (± 0.66%) +0.00s (+ 0.00%) 0.55s 0.56s
Check Time 7.14s (± 0.59%) 7.15s (± 0.88%) +0.01s (+ 0.21%) 7.05s 7.29s
Emit Time 2.26s (± 1.27%) 2.26s (± 0.55%) -0.01s (- 0.27%) 2.23s 2.28s
Total Time 10.76s (± 0.51%) 10.78s (± 0.60%) +0.02s (+ 0.17%) 10.63s 10.94s
Monaco - node (v14.15.1, x64)
Memory used 322,517k (± 0.01%) 322,624k (± 0.00%) +107k (+ 0.03%) 322,576k 322,651k
Parse Time 1.46s (± 0.51%) 1.46s (± 0.44%) -0.00s (- 0.07%) 1.45s 1.48s
Bind Time 0.74s (± 0.46%) 0.75s (± 0.78%) +0.00s (+ 0.54%) 0.74s 0.76s
Check Time 5.17s (± 0.23%) 5.19s (± 0.40%) +0.01s (+ 0.27%) 5.15s 5.23s
Emit Time 3.07s (± 0.58%) 3.08s (± 0.76%) +0.01s (+ 0.46%) 3.04s 3.15s
Total Time 10.45s (± 0.26%) 10.48s (± 0.36%) +0.03s (+ 0.26%) 10.40s 10.55s
TFS - node (v14.15.1, x64)
Memory used 287,631k (± 0.00%) 287,602k (± 0.01%) -29k (- 0.01%) 287,554k 287,638k
Parse Time 1.24s (± 0.97%) 1.23s (± 0.85%) -0.01s (- 0.81%) 1.21s 1.25s
Bind Time 0.71s (± 0.87%) 0.72s (± 1.16%) +0.01s (+ 0.70%) 0.70s 0.74s
Check Time 4.80s (± 0.40%) 4.80s (± 0.40%) -0.00s (- 0.06%) 4.77s 4.85s
Emit Time 3.23s (± 1.03%) 3.25s (± 0.84%) +0.02s (+ 0.62%) 3.19s 3.31s
Total Time 9.99s (± 0.43%) 10.00s (± 0.41%) +0.01s (+ 0.13%) 9.90s 10.07s
material-ui - node (v14.15.1, x64)
Memory used 448,641k (± 0.00%) 450,606k (± 0.01%) +1,965k (+ 0.44%) 450,564k 450,691k
Parse Time 1.74s (± 0.42%) 1.75s (± 0.79%) +0.01s (+ 0.52%) 1.72s 1.79s
Bind Time 0.69s (± 0.58%) 0.69s (± 0.83%) -0.00s (- 0.14%) 0.68s 0.70s
Check Time 12.93s (± 0.62%) 13.63s (± 0.48%) +0.70s (+ 5.42%) 13.51s 13.82s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.36s (± 0.54%) 16.07s (± 0.37%) +0.71s (+ 4.63%) 15.93s 16.23s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory1 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
Benchmark Name Iterations
Current 44512 10
Baseline master 10

Developer Information:

Download Benchmark

@c69-addepar
Copy link

@c69-addepar c69-addepar commented Jun 10, 2021

We furthermore permit index signature declarations to specify union key types, provided all constituents are either string, number, symbol, or template literal types with non-generic placeholders

are literal string unions allowed inside the template string types ? eg:

type CoordinateProps = {
    [key: `${'x'|'y'|'z'}`]: number;
};
@ahejlsberg
Copy link
Member Author

@ahejlsberg ahejlsberg commented Jun 10, 2021

are literal string unions allowed inside the template string types

No, the type `${'x'|'y'|'z'}` is equivalent to 'x' | 'y' | 'z', which isn't permitted. But you can of course use Record<'x' | 'y' | 'z', number>, which resolves to three distinct properties.

@ahejlsberg
Copy link
Member Author

@ahejlsberg ahejlsberg commented Jun 10, 2021

@typescript-bot perf test this

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jun 10, 2021

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

Update: The results are in!

@typescript-bot
Copy link
Collaborator

@typescript-bot typescript-bot commented Jun 10, 2021

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

Here they are:

Comparison Report - master..44512

Metric master 44512 Delta Best Worst
Angular - node (v10.16.3, x64)
Memory used 343,935k (± 0.03%) 344,007k (± 0.02%) +72k (+ 0.02%) 343,838k 344,182k
Parse Time 1.79s (± 0.25%) 1.79s (± 0.74%) +0.00s (+ 0.28%) 1.77s 1.83s
Bind Time 0.84s (± 0.69%) 0.84s (± 0.62%) +0.00s (+ 0.48%) 0.83s 0.85s
Check Time 5.18s (± 0.36%) 5.18s (± 0.59%) +0.00s (+ 0.06%) 5.15s 5.29s
Emit Time 5.47s (± 0.58%) 5.48s (± 0.82%) +0.01s (+ 0.22%) 5.41s 5.64s
Total Time 13.28s (± 0.35%) 13.30s (± 0.46%) +0.02s (+ 0.15%) 13.19s 13.45s
Compiler-Unions - node (v10.16.3, x64)
Memory used 200,424k (± 0.06%) 200,543k (± 0.03%) +119k (+ 0.06%) 200,415k 200,643k
Parse Time 0.78s (± 0.77%) 0.78s (± 0.71%) +0.01s (+ 0.77%) 0.77s 0.79s
Bind Time 0.53s (± 1.44%) 0.53s (± 1.10%) +0.00s (+ 0.19%) 0.51s 0.54s
Check Time 7.55s (± 0.60%) 7.52s (± 0.27%) -0.03s (- 0.37%) 7.48s 7.55s
Emit Time 2.27s (± 0.85%) 2.24s (± 1.46%) -0.03s (- 1.19%) 2.19s 2.36s
Total Time 11.12s (± 0.50%) 11.07s (± 0.32%) -0.05s (- 0.44%) 11.01s 11.18s
Monaco - node (v10.16.3, x64)
Memory used 340,462k (± 0.02%) 340,104k (± 0.01%) -358k (- 0.11%) 339,983k 340,196k
Parse Time 1.44s (± 0.79%) 1.45s (± 0.61%) +0.01s (+ 0.76%) 1.43s 1.47s
Bind Time 0.74s (± 0.70%) 0.74s (± 0.88%) -0.00s (- 0.14%) 0.73s 0.76s
Check Time 5.33s (± 0.62%) 5.31s (± 0.23%) -0.02s (- 0.38%) 5.29s 5.35s
Emit Time 2.96s (± 1.09%) 2.96s (± 0.83%) -0.01s (- 0.20%) 2.93s 3.03s
Total Time 10.48s (± 0.34%) 10.46s (± 0.25%) -0.02s (- 0.17%) 10.42s 10.53s
TFS - node (v10.16.3, x64)
Memory used 304,041k (± 0.02%) 303,391k (± 0.02%) -650k (- 0.21%) 303,247k 303,558k
Parse Time 1.18s (± 0.47%) 1.18s (± 0.52%) +0.00s (+ 0.25%) 1.17s 1.20s
Bind Time 0.70s (± 0.83%) 0.70s (± 0.68%) 0.00s ( 0.00%) 0.69s 0.71s
Check Time 4.85s (± 0.46%) 4.84s (± 0.32%) -0.00s (- 0.06%) 4.80s 4.88s
Emit Time 3.04s (± 1.03%) 3.04s (± 1.36%) +0.01s (+ 0.30%) 2.95s 3.12s
Total Time 9.76s (± 0.51%) 9.77s (± 0.53%) +0.01s (+ 0.08%) 9.64s 9.87s
material-ui - node (v10.16.3, x64)
Memory used 471,636k (± 0.02%) 473,299k (± 0.01%) +1,662k (+ 0.35%) 473,237k 473,348k
Parse Time 1.72s (± 0.27%) 1.72s (± 0.41%) -0.00s (- 0.06%) 1.71s 1.73s
Bind Time 0.66s (± 0.87%) 0.66s (± 0.93%) +0.00s (+ 0.15%) 0.65s 0.67s
Check Time 14.22s (± 0.59%) 14.79s (± 0.51%) +0.58s (+ 4.06%) 14.66s 15.07s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 16.60s (± 0.51%) 17.17s (± 0.46%) +0.58s (+ 3.48%) 17.04s 17.46s
Angular - node (v12.1.0, x64)
Memory used 322,171k (± 0.02%) 322,317k (± 0.02%) +145k (+ 0.05%) 322,158k 322,489k
Parse Time 1.77s (± 0.53%) 1.77s (± 0.74%) +0.00s (+ 0.06%) 1.75s 1.81s
Bind Time 0.83s (± 0.97%) 0.82s (± 0.41%) -0.01s (- 0.60%) 0.82s 0.83s
Check Time 5.07s (± 0.41%) 5.09s (± 0.34%) +0.02s (+ 0.34%) 5.06s 5.14s
Emit Time 5.65s (± 0.63%) 5.67s (± 0.43%) +0.02s (+ 0.27%) 5.60s 5.72s
Total Time 13.32s (± 0.38%) 13.35s (± 0.35%) +0.02s (+ 0.18%) 13.25s 13.46s
Compiler-Unions - node (v12.1.0, x64)
Memory used 187,842k (± 0.07%) 187,984k (± 0.07%) +142k (+ 0.08%) 187,573k 188,192k
Parse Time 0.77s (± 0.61%) 0.77s (± 0.67%) +0.00s (+ 0.13%) 0.76s 0.78s
Bind Time 0.53s (± 1.13%) 0.53s (± 0.65%) +0.00s (+ 0.19%) 0.52s 0.53s
Check Time 7.00s (± 0.51%) 6.99s (± 0.60%) -0.02s (- 0.21%) 6.92s 7.13s
Emit Time 2.23s (± 0.58%) 2.25s (± 0.83%) +0.02s (+ 0.72%) 2.22s 2.30s
Total Time 10.52s (± 0.37%) 10.53s (± 0.46%) +0.01s (+ 0.05%) 10.44s 10.65s
Monaco - node (v12.1.0, x64)
Memory used 323,452k (± 0.02%) 323,092k (± 0.06%) -359k (- 0.11%) 322,400k 323,333k
Parse Time 1.41s (± 0.54%) 1.42s (± 0.54%) +0.00s (+ 0.07%) 1.40s 1.43s
Bind Time 0.72s (± 0.93%) 0.72s (± 1.06%) -0.00s (- 0.14%) 0.71s 0.74s
Check Time 5.20s (± 0.47%) 5.17s (± 0.30%) -0.04s (- 0.75%) 5.12s 5.19s
Emit Time 2.99s (± 0.43%) 3.01s (± 1.03%) +0.02s (+ 0.80%) 2.97s 3.09s
Total Time 10.33s (± 0.32%) 10.31s (± 0.36%) -0.02s (- 0.15%) 10.25s 10.43s
TFS - node (v12.1.0, x64)
Memory used 288,599k (± 0.02%) 288,021k (± 0.01%) -578k (- 0.20%) 287,897k 288,123k
Parse Time 1.18s (± 0.69%) 1.19s (± 0.64%) +0.00s (+ 0.17%) 1.17s 1.21s
Bind Time 0.70s (± 2.30%) 0.68s (± 1.00%) -0.02s (- 2.15%) 0.67s 0.70s
Check Time 4.78s (± 0.48%) 4.74s (± 0.57%) -0.04s (- 0.79%) 4.70s 4.80s
Emit Time 3.12s (± 0.59%) 3.12s (± 0.93%) -0.00s (- 0.06%) 3.06s 3.19s
Total Time 9.78s (± 0.46%) 9.73s (± 0.56%) -0.06s (- 0.57%) 9.64s 9.86s
material-ui - node (v12.1.0, x64)
Memory used 450,177k (± 0.06%) 451,863k (± 0.08%) +1,686k (+ 0.37%) 450,808k 452,260k
Parse Time 1.71s (± 0.23%) 1.71s (± 0.41%) -0.00s (- 0.12%) 1.69s 1.72s
Bind Time 0.63s (± 0.57%) 0.64s (± 0.78%) +0.00s (+ 0.16%) 0.63s 0.65s
Check Time 12.74s (± 0.53%) 13.32s (± 0.80%) +0.58s (+ 4.54%) 13.16s 13.60s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.09s (± 0.48%) 15.67s (± 0.70%) +0.58s (+ 3.82%) 15.48s 15.95s
Angular - node (v14.15.1, x64)
Memory used 320,917k (± 0.01%) 320,961k (± 0.00%) +44k (+ 0.01%) 320,919k 320,998k
Parse Time 1.78s (± 0.26%) 1.79s (± 0.36%) +0.01s (+ 0.67%) 1.78s 1.81s
Bind Time 0.87s (± 0.57%) 0.87s (± 0.60%) +0.01s (+ 0.58%) 0.86s 0.89s
Check Time 5.08s (± 0.27%) 5.12s (± 0.55%) +0.05s (+ 0.91%) 5.05s 5.19s
Emit Time 5.71s (± 0.58%) 5.72s (± 0.91%) +0.01s (+ 0.25%) 5.63s 5.81s
Total Time 13.43s (± 0.32%) 13.51s (± 0.52%) +0.08s (+ 0.57%) 13.38s 13.67s
Compiler-Unions - node (v14.15.1, x64)
Memory used 188,442k (± 0.67%) 188,338k (± 0.63%) -105k (- 0.06%) 186,701k 189,983k
Parse Time 0.80s (± 0.37%) 0.80s (± 0.42%) -0.00s (- 0.25%) 0.79s 0.81s
Bind Time 0.55s (± 0.66%) 0.55s (± 0.90%) +0.00s (+ 0.18%) 0.55s 0.57s
Check Time 7.14s (± 0.59%) 7.10s (± 0.57%) -0.04s (- 0.49%) 7.04s 7.23s
Emit Time 2.26s (± 1.27%) 2.27s (± 1.13%) +0.01s (+ 0.35%) 2.21s 2.34s
Total Time 10.76s (± 0.51%) 10.73s (± 0.55%) -0.03s (- 0.30%) 10.62s 10.90s
Monaco - node (v14.15.1, x64)
Memory used 322,517k (± 0.01%) 322,169k (± 0.01%) -348k (- 0.11%) 322,134k 322,231k
Parse Time 1.46s (± 0.51%) 1.46s (± 0.55%) -0.01s (- 0.34%) 1.44s 1.48s
Bind Time 0.74s (± 0.46%) 0.74s (± 0.66%) +0.00s (+ 0.13%) 0.74s 0.76s
Check Time 5.17s (± 0.23%) 5.14s (± 0.44%) -0.03s (- 0.62%) 5.09s 5.20s
Emit Time 3.07s (± 0.58%) 3.07s (± 0.95%) -0.00s (- 0.03%) 3.02s 3.16s
Total Time 10.45s (± 0.26%) 10.42s (± 0.29%) -0.04s (- 0.33%) 10.34s 10.47s
TFS - node (v14.15.1, x64)
Memory used 287,631k (± 0.00%) 287,108k (± 0.01%) -523k (- 0.18%) 287,077k 287,158k
Parse Time 1.24s (± 0.97%) 1.24s (± 0.89%) 0.00s ( 0.00%) 1.22s 1.27s
Bind Time 0.71s (± 0.87%) 0.71s (± 0.81%) -0.00s (- 0.14%) 0.70s 0.73s
Check Time 4.80s (± 0.40%) 4.76s (± 0.18%) -0.04s (- 0.88%) 4.73s 4.77s
Emit Time 3.23s (± 1.03%) 3.22s (± 0.90%) -0.01s (- 0.43%) 3.16s 3.27s
Total Time 9.99s (± 0.43%) 9.93s (± 0.31%) -0.06s (- 0.58%) 9.86s 10.00s
material-ui - node (v14.15.1, x64)
Memory used 448,641k (± 0.00%) 450,296k (± 0.06%) +1,655k (+ 0.37%) 449,168k 450,467k
Parse Time 1.74s (± 0.42%) 1.74s (± 0.44%) -0.00s (- 0.17%) 1.72s 1.76s
Bind Time 0.69s (± 0.58%) 0.68s (± 0.73%) -0.01s (- 0.87%) 0.68s 0.70s
Check Time 12.93s (± 0.62%) 13.51s (± 0.91%) +0.59s (+ 4.55%) 13.32s 13.86s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.36s (± 0.54%) 15.94s (± 0.82%) +0.58s (+ 3.79%) 15.74s 16.29s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-206-generic
Architecturex64
Available Memory16 GB
Available Memory1 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v10.16.3, x64)
  • node (v12.1.0, x64)
  • node (v14.15.1, x64)
Scenarios
  • Angular - node (v10.16.3, x64)
  • Angular - node (v12.1.0, x64)
  • Angular - node (v14.15.1, x64)
  • Compiler-Unions - node (v10.16.3, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Compiler-Unions - node (v14.15.1, x64)
  • Monaco - node (v10.16.3, x64)
  • Monaco - node (v12.1.0, x64)
  • Monaco - node (v14.15.1, x64)
  • TFS - node (v10.16.3, x64)
  • TFS - node (v12.1.0, x64)
  • TFS - node (v14.15.1, x64)
  • material-ui - node (v10.16.3, x64)
  • material-ui - node (v12.1.0, x64)
  • material-ui - node (v14.15.1, x64)
Benchmark Name Iterations
Current 44512 10
Baseline master 10

Developer Information:

Download Benchmark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment