GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support re-aliasing of type alias instantiations by ahejlsberg · Pull Request #42284 · microsoft/TypeScript

Conversation

@ahejlsberg

@ahejlsberg Anders Hejlsberg (ahejlsberg) commented Jan 11, 2021

Copy link
Copy Markdown
Member

This PR continues the work in #42149 by supporting re-aliasing of type alias instantiations. For example:

type Thing<T> = { value: T };
type ArrayThing<U> = Thing<U[]>;
type StringArrayThing = ArrayThing<string>;

declare let t1: Thing<string[]>;     // Thing<string[]>
declare let t2: ArrayThing<string>;  // ArrayThing<string> (previously Thing<string[]>)
declare let t3: StringArrayThing;    // StringArrayThing (previously Thing<string[]>)

interface Item<T> { value: T }
type ArrayItem<U> = Item<U[]>;
type NumberArrayItem = ArrayItem<number>;

declare let t4: Item<number[]>;     // Item<number[]>
declare let t5: ArrayItem<number>;  // ArrayItem<number>
declare let t6: NumberArrayItem;    // NumberArrayItem (previously ArrayItem<number>)

function foo<T, K extends keyof T>(obj: T, key: K) {
    let x: Omit<T, K>;  // Omit<T, K> (previously Pick<T, Exclude<keyof T, K>>)
}

Previously, instantiations of aliased anonymous object, mapped, or conditional types with a new type alias would continue to display the original type alias in diagnostics, quick info, and declaration files. Now, re-aliasing of such types consistently adopts and displays the new type alias.

In addition, instantiations of distributive types (such as homomorphic mapped types and distributive conditional types) now properly preserve the original type alias when the instantiation results in a union type:

type A = { a: string };
type B = { b: string };

declare let p: Partial<A | B>;  // Partial<A | B> (previously Partial<A> | Partial<B>)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

levenleven, NoelAbrahams, mrThomasTeller, jasonkuhrt, and zhao5363 reacted with thumbs up emoji robpalme, hassannteifeh, fvilante, biocomputer924, NoelAbrahams, jasonkuhrt, and zhao5363 reacted with hooray emoji AviVahl, fvilante, NoelAbrahams, and jasonkuhrt reacted with rocket emoji
All reactions
  • 👍 5 reactions
  • 🎉 7 reactions
  • 🚀 4 reactions
Anders Hejlsberg (ahejlsberg) added 5 commits January 8, 2021 16:33
@ahejlsberg
New aliases for type alias instantiations
a4a47db
@ahejlsberg
New aliases for conditional, mapped, and anonymous object type instan…
0c6dfb7
…tiations
@ahejlsberg
Accept new baselines
54da2a4
@ahejlsberg
Fix issues with re-aliasing
1b0d12e
@ahejlsberg
Accept new baselines
8ac7030
@typescript-bot TypeScript Bot (typescript-bot) assigned Anders Hejlsberg (ahejlsberg) Jan 11, 2021
@typescript-bot TypeScript Bot (typescript-bot) added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jan 11, 2021
@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Jan 11, 2021

Copy link
Copy Markdown
Member Author

TypeScript Bot (@typescript-bot) test this
TypeScript Bot (@typescript-bot) user test this
TypeScript Bot (@typescript-bot) run dt
TypeScript Bot (@typescript-bot) perf test this faster

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 11, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the abridged perf test suite on this PR at 8ac7030. You can monitor the build here.

Update: The results are in!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 11, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized community code test suite on this PR at 8ac7030. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 11, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the extended test suite on this PR at 8ac7030. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 11, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Anders Hejlsberg (@ahejlsberg), I've started to run the parallelized Definitely Typed test suite on this PR at 8ac7030. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Jan 11, 2021

Copy link
Copy Markdown
Member Author

Rob Palmer (@robpalme) This is the continuation PR I mentioned in #42149. Give it a try and let me know how it goes.

robpalme reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 11, 2021

Copy link
Copy Markdown
Contributor

Anders Hejlsberg (@ahejlsberg)
The results of the perf run you requested are in!

Here they are:

Comparison Report - master..42284

Metric master 42284 Delta Best Worst
Angular - node (v12.1.0, x64)
Memory used 324,053k (± 0.02%) 324,025k (± 0.02%) -28k (- 0.01%) 323,871k 324,182k
Parse Time 1.98s (± 0.66%) 1.99s (± 0.84%) +0.01s (+ 0.50%) 1.95s 2.01s
Bind Time 0.81s (± 0.92%) 0.82s (± 1.35%) +0.00s (+ 0.49%) 0.81s 0.86s
Check Time 4.88s (± 0.33%) 4.88s (± 0.58%) +0.01s (+ 0.21%) 4.82s 4.94s
Emit Time 5.51s (± 0.77%) 5.51s (± 0.61%) -0.00s (- 0.02%) 5.46s 5.59s
Total Time 13.18s (± 0.43%) 13.21s (± 0.50%) +0.03s (+ 0.21%) 13.06s 13.36s
Compiler-Unions - node (v12.1.0, x64)
Memory used 200,247k (± 0.08%) 200,294k (± 0.07%) +47k (+ 0.02%) 199,982k 200,507k
Parse Time 0.78s (± 0.77%) 0.77s (± 0.98%) -0.00s (- 0.00%) 0.76s 0.79s
Bind Time 0.50s (± 0.66%) 0.50s (± 1.04%) -0.00s (- 0.20%) 0.49s 0.51s
Check Time 9.94s (± 1.06%) 9.92s (± 0.79%) -0.02s (- 0.17%) 9.75s 10.15s
Emit Time 2.37s (± 0.97%) 2.36s (± 1.29%) -0.01s (- 0.42%) 2.30s 2.46s
Total Time 13.58s (± 0.74%) 13.55s (± 0.70%) -0.03s (- 0.23%) 13.34s 13.75s
Monaco - node (v12.1.0, x64)
Memory used 337,446k (± 0.03%) 337,473k (± 0.01%) +27k (+ 0.01%) 337,335k 337,541k
Parse Time 1.59s (± 0.30%) 1.58s (± 0.56%) -0.00s (- 0.31%) 1.57s 1.61s
Bind Time 0.70s (± 1.08%) 0.70s (± 0.64%) -0.01s (- 0.99%) 0.69s 0.71s
Check Time 4.95s (± 0.46%) 4.94s (± 0.43%) -0.01s (- 0.12%) 4.88s 4.98s
Emit Time 2.88s (± 0.60%) 2.89s (± 0.42%) +0.01s (+ 0.38%) 2.86s 2.91s
Total Time 10.12s (± 0.24%) 10.11s (± 0.36%) -0.01s (- 0.06%) 9.99s 10.16s
TFS - node (v12.1.0, x64)
Memory used 292,356k (± 0.02%) 292,396k (± 0.02%) +41k (+ 0.01%) 292,282k 292,533k
Parse Time 1.25s (± 0.76%) 1.25s (± 0.71%) -0.01s (- 0.64%) 1.23s 1.26s
Bind Time 0.65s (± 0.73%) 0.65s (± 0.86%) -0.01s (- 0.77%) 0.64s 0.66s
Check Time 4.54s (± 0.70%) 4.52s (± 0.54%) -0.02s (- 0.51%) 4.47s 4.58s
Emit Time 2.95s (± 0.89%) 2.94s (± 0.72%) -0.00s (- 0.14%) 2.90s 2.98s
Total Time 9.40s (± 0.52%) 9.36s (± 0.42%) -0.04s (- 0.37%) 9.28s 9.45s
material-ui - node (v12.1.0, x64)
Memory used 478,950k (± 0.07%) 473,781k (± 0.01%) -5,169k (- 1.08%) 473,585k 473,886k
Parse Time 2.08s (± 0.73%) 2.07s (± 0.54%) -0.02s (- 0.91%) 2.04s 2.09s
Bind Time 0.65s (± 0.73%) 0.64s (± 0.69%) -0.00s (- 0.77%) 0.63s 0.65s
Check Time 12.49s (± 0.90%) 12.51s (± 0.71%) +0.02s (+ 0.14%) 12.28s 12.72s
Emit Time 0.00s (± 0.00%) 0.00s (± 0.00%) 0.00s ( NaN%) 0.00s 0.00s
Total Time 15.23s (± 0.65%) 15.22s (± 0.62%) -0.00s (- 0.03%) 14.98s 15.44s
System
Machine Namets-ci-ubuntu
Platformlinux 4.4.0-197-generic
Architecturex64
Available Memory16 GB
Available Memory4 GB
CPUs4 × Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
Hosts
  • node (v12.1.0, x64)
Scenarios
  • Angular - node (v12.1.0, x64)
  • Compiler-Unions - node (v12.1.0, x64)
  • Monaco - node (v12.1.0, x64)
  • TFS - node (v12.1.0, x64)
  • material-ui - node (v12.1.0, x64)
Benchmark Name Iterations
Current 42284 10
Baseline master 10

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot TypeScript Bot (typescript-bot) mentioned this pull request Jan 11, 2021
🤖 User test baselines have changed for newAliasesForInstantiatedTypes typescript-bot/TypeScript#131
Open
@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 11, 2021

Copy link
Copy Markdown
Contributor

The user suite test run you requested has finished and failed. I've opened a PR with the baseline diff from master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ahejlsberg
Anders Hejlsberg (ahejlsberg) requested review from Daniel Rosenwasser (DanielRosenwasser), Ryan Cavanaugh (RyanCavanaugh), Ron Buckton (rbuckton) and Wesley Wigham (weswigham) January 11, 2021 19:30
@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Jan 11, 2021

Copy link
Copy Markdown
Member Author

Tests all look good, only changes are improved diagnostics. Performance is unaffected.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@DanielRosenwasser

Daniel Rosenwasser (DanielRosenwasser) commented Jan 11, 2021

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) pack this

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 11, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Heya Daniel Rosenwasser (@DanielRosenwasser), I've started to run the tarball bundle task on this PR at 8ac7030. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@typescript-bot

TypeScript Bot (typescript-bot) commented Jan 11, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Hey Daniel Rosenwasser (@DanielRosenwasser), 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/93139/artifacts?artifactName=tgz&fileId=4FE49FBE4115C3F38EC02DE524EF9087A6729DD9744C9B257007FE5D69F77D1202&fileName=/typescript-4.2.0-insiders.20210111.tgz"
    }
}

and then running npm install.


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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) approved these changes Jan 11, 2021
View reviewed changes
Comment thread tests/baselines/reference/conditionalTypes1.errors.txt
Comment on lines +209 to +214
!!! error TS2322: Type 'keyof T' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
!!! error TS2322: Type 'string' is not assignable to type 'T[keyof T] extends Function ? never : keyof T'.
!!! error TS2322: Type 'keyof T' is not assignable to type 'never'.
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'never'.
!!! error TS2322: Type 'string' is not assignable to type 'never'.

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Jan 11, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why's this happening? What was avoiding the elaboration before?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Jan 11, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Sounds like we can't avoid re-elaboration based on type IDs

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ahejlsberg
Anders Hejlsberg (ahejlsberg) merged commit c456bbd into master Jan 11, 2021
@DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser) deleted the newAliasesForInstantiatedTypes branch January 12, 2021 00:20
@Kingwl Wenlu Wang (Kingwl) mentioned this pull request Jan 12, 2021
Add inlay hints support #42089
Merged
10 tasks done
@robpalme

Rob Palmer (robpalme) commented Jan 12, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Anders Hejlsberg (@ahejlsberg) This is even better than the previous attempt 🎉

As before, there are no inlining/size regressions - I reviewed every changed line and this PR is a pure win. This PR improves upon 2c2d06d by also handling aliases to Record and Pick<obj, union>.

// Previous: 2c2d06
  myRecordProp: Record<string, any>;
  myObjectProp: Pick<{
      lotsOfProps,
    }, "red" | "green" | "blue
  >;

...is replaced by...

// Master: Using PR#42284
  myRecordProp: MyRecordType;
  myObjectProp: MyColorsOnly<{
      lotsOfProps,
    }
  >;

On the large package I referred to in previous reports, this PR results in a further 10KB decrease vs the previous attempt, i.e the Record & Pick changes explains the 10KB win. Meaning the net effect of this PR is now:

  • 50 declaration files out of 394 were affected by this PR
  • Net size of all declaration files shrank by 41KB
    • 50 files shrank (total size of these files reduced by 41KB from 585KB to 544KB)
    • 0 files grew
ahejlsberg and treybrisbane reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sandersn Nathan Shively-Sanders (sandersn) mentioned this pull request Jan 13, 2021
jquery has batch-only inference error after re-aliasing support (##42284) #42317
Closed
@danvk Dan Vanderkam (danvk) mentioned this pull request Jan 13, 2021
TS 4.2 beta preserves "keyof" expressions in type display #42322
Closed
Zzzen (Zzzen) pushed a commit to Zzzen/TypeScript that referenced this pull request Jan 16, 2021
@ahejlsberg @Zzzen
Support re-aliasing of type alias instantiations (microsoft#42284)
3bd1ef6
* New aliases for type alias instantiations

* New aliases for conditional, mapped, and anonymous object type instantiations

* Accept new baselines

* Fix issues with re-aliasing

* Accept new baselines
@ahejlsberg Anders Hejlsberg (ahejlsberg) mentioned this pull request Jan 22, 2021
react-redux: conditional type inference from alias fails after re-alias support in #42284 #42421
Closed
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) added this to the TypeScript 4.2.0 milestone Jan 22, 2021
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request Jan 28, 2021
Use homomorphic templated type for Omit #42524
Closed
@ahejlsberg Anders Hejlsberg (ahejlsberg) mentioned this pull request Mar 29, 2021
Conditional type inference regression in 4.2* #43192
Closed
@amcasey Andrew Casey (amcasey) mentioned this pull request Apr 13, 2021
React HOCs generate extremely large and incorrect .d.ts declaration files, regression from 4.1.3 #43622
Closed
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request Apr 20, 2021
Design Meeting Notes, 4/14/2021 #43743
Closed
@ahejlsberg Anders Hejlsberg (ahejlsberg) mentioned this pull request May 26, 2021
TS 4.2: Type alias differs from original type #44119
Closed
@jakebailey Jake Bailey (jakebailey) mentioned this pull request Oct 7, 2021
Lengthy type being shown instead of alias microsoft/pylance-release#1914
Closed
@jcalz Joe Calzaretta (jcalz) mentioned this pull request Mar 1, 2022
Conditional type evaluation of type aliases produces different result than their equivalent substitution #48070
Open
@rbuckton Ron Buckton (rbuckton) mentioned this pull request Apr 5, 2022
Write more useful types in .types test outputs #48578
Merged
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) mentioned this pull request Apr 19, 2022
Infer operator returning container type instead of applied generic #48772
Closed
@ahejlsberg Anders Hejlsberg (ahejlsberg) mentioned this pull request Sep 12, 2023
Method infers the wrong type when passing a value that is typealiased that uses union and intersection types #55648
Closed
@ddurschlag ddurschlag mentioned this pull request Oct 12, 2023
Improve type readability (fix type alias propagation, allow aliasing inferred types) #45954
Open
@mikearnaldi Michael Arnaldi (mikearnaldi) mentioned this pull request Apr 15, 2025
Aliases are lost when conditionals are applied #61581
Closed
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) DanielRosenwasser approved these changes
@weswigham Wesley Wigham (weswigham) Awaiting requested review from weswigham
@rbuckton Ron Buckton (rbuckton) Awaiting requested review from rbuckton
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) Awaiting requested review from RyanCavanaugh

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@ahejlsberg Anders Hejlsberg (ahejlsberg)

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Milestone

TypeScript 4.2.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@ahejlsberg @typescript-bot @DanielRosenwasser @robpalme
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.