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

Support re-aliasing of type alias instantiations #42284

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.

Sign up for GitHub

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

Merged
Anders Hejlsberg (ahejlsberg) merged 5 commits into master from newAliasesForInstantiatedTypes
Jan 11, 2021

Uh oh!

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

Merged

Support re-aliasing of type alias instantiations #42284

Changes from 1 commit
Commits
Show all changes
5 commits
Select commit Hold shift + click to select a range
a4a47db
New aliases for type alias instantiations
ahejlsberg Jan 9, 2021
0c6dfb7
New aliases for conditional, mapped, and anonymous object type instan…
ahejlsberg Jan 9, 2021
54da2a4
Accept new baselines
ahejlsberg Jan 9, 2021
1b0d12e
Fix issues with re-aliasing
ahejlsberg Jan 11, 2021
8ac7030
Accept new baselines
ahejlsberg Jan 11, 2021
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

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

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

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

Diff view
Diff view
Prev Previous commit
Next Next commit
Fix issues with re-aliasing
  • Loading branch information

Uh oh!

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

@ahejlsberg
ahejlsberg committed Jan 11, 2021
commit 1b0d12ea503ad8bc9d692137a3fdd2f300124784

There are no files selected for viewing

36 changes: 19 additions & 17 deletions 36 src/compiler/checker.ts
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -12361,15 +12361,18 @@ namespace ts {
return type;
}

function createDeferredTypeReference(target: GenericType, node: TypeReferenceNode | ArrayTypeNode | TupleTypeNode, mapper?: TypeMapper): DeferredTypeReference {
const aliasSymbol = getAliasSymbolForTypeNode(node);
const aliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
function createDeferredTypeReference(target: GenericType, node: TypeReferenceNode | ArrayTypeNode | TupleTypeNode, mapper?: TypeMapper, aliasSymbol?: Symbol, aliasTypeArguments?: readonly Type[]): DeferredTypeReference {
if (!aliasSymbol) {
aliasSymbol = getAliasSymbolForTypeNode(node);
const localAliasTypeArguments = getTypeArgumentsForAliasSymbol(aliasSymbol);
aliasTypeArguments = mapper ? instantiateTypes(localAliasTypeArguments, mapper) : localAliasTypeArguments;
}
const type = <DeferredTypeReference>createObjectType(ObjectFlags.Reference, target.symbol);
type.target = target;
type.node = node;
type.mapper = mapper;
type.aliasSymbol = aliasSymbol;
type.aliasTypeArguments = mapper ? instantiateTypes(aliasTypeArguments, mapper) : aliasTypeArguments;
type.aliasTypeArguments = aliasTypeArguments;
return type;
}

Expand Down Expand Up @@ -15460,17 +15463,19 @@ namespace ts {
// instantiation cache key from the type IDs of the type arguments.
const combinedMapper = combineTypeMappers(type.mapper, mapper);
const typeArguments = map(typeParameters, t => getMappedType(t, combinedMapper));
const id = getTypeListId(typeArguments) + (aliasSymbol ? `@${getSymbolId(aliasSymbol)}` : "");
const newAliasSymbol = aliasSymbol || type.aliasSymbol;
const id = getTypeListId(typeArguments) + (newAliasSymbol ? `@${getSymbolId(newAliasSymbol)}` : "");
if (!target.instantiations) {
target.instantiations = new Map<string, Type>();
target.instantiations.set(getTypeListId(typeParameters), target);
target.instantiations.set(getTypeListId(typeParameters) + (target.aliasSymbol ? `@${getSymbolId(target.aliasSymbol)}` : ""), target);
}
let result = target.instantiations.get(id);
if (!result) {
const newMapper = createTypeMapper(typeParameters, typeArguments);
result = target.objectFlags & ObjectFlags.Reference ? createDeferredTypeReference((<DeferredTypeReference>type).target, (<DeferredTypeReference>type).node, newMapper) :
target.objectFlags & ObjectFlags.Mapped ? instantiateMappedType(<MappedType>target, newMapper, aliasSymbol, aliasTypeArguments) :
instantiateAnonymousType(target, newMapper, aliasSymbol, aliasTypeArguments);
const newAliasTypeArguments = aliasSymbol ? aliasTypeArguments : instantiateTypes(type.aliasTypeArguments, mapper);
result = target.objectFlags & ObjectFlags.Reference ? createDeferredTypeReference((<DeferredTypeReference>type).target, (<DeferredTypeReference>type).node, newMapper, newAliasSymbol, newAliasTypeArguments) :
target.objectFlags & ObjectFlags.Mapped ? instantiateMappedType(<MappedType>target, newMapper, newAliasSymbol, newAliasTypeArguments) :
instantiateAnonymousType(target, newMapper, newAliasSymbol, newAliasTypeArguments);
target.instantiations.set(id, result);
}
return result;
Expand Down Expand Up @@ -15694,15 +15699,12 @@ namespace ts {
}
if (flags & TypeFlags.Object) {
const objectFlags = (<ObjectType>type).objectFlags;
if (objectFlags & ObjectFlags.Reference) {
if ((<TypeReference>type).node) {
return getObjectTypeInstantiation(<TypeReference | AnonymousType | MappedType>type, mapper);
if (objectFlags & (ObjectFlags.Reference | ObjectFlags.Anonymous | ObjectFlags.Mapped)) {
if (objectFlags & ObjectFlags.Reference && !(<TypeReference>type).node) {
const resolvedTypeArguments = (<TypeReference>type).resolvedTypeArguments;
const newTypeArguments = instantiateTypes(resolvedTypeArguments, mapper);
return newTypeArguments !== resolvedTypeArguments ? createNormalizedTypeReference((<TypeReference>type).target, newTypeArguments) : type;
}
const resolvedTypeArguments = (<TypeReference>type).resolvedTypeArguments;
const newTypeArguments = instantiateTypes(resolvedTypeArguments, mapper);
return newTypeArguments !== resolvedTypeArguments ? createNormalizedTypeReference((<TypeReference>type).target, newTypeArguments) : type;
}
if (objectFlags & (ObjectFlags.Anonymous | ObjectFlags.Mapped)) {
return getObjectTypeInstantiation(<TypeReference | AnonymousType | MappedType>type, mapper, aliasSymbol, aliasTypeArguments);
}
return type;
Expand Down
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 01402520 — 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.