-
Notifications
You must be signed in to change notification settings - Fork 12.9k
[Release-2.0.5] Fix 11035: missing generic in .d.ts emit #11154
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2121,12 +2121,16 @@ namespace ts { | |
} | ||
|
||
function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, symbolStack?: Symbol[]) { | ||
const globalFlagsToPass = globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike; | ||
let globalFlagsToPass = globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let globalFlagsToPass = globalFlags & (TypeFormatFlags.WriteOwnNameForAnyLike | TypeFormatFlags.UseTypeAliasValue);```
Is similar change needed in master? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not at all. So this is just address an issue for release-2.0.5 the master uses accessibility check (check accessibility allows we to correctly check local type) |
||
if (globalFlags & TypeFormatFlags.UseTypeAliasValue) { | ||
globalFlagsToPass |= TypeFormatFlags.UseTypeAliasValue; | ||
} | ||
let inObjectTypeLiteral = false; | ||
return writeType(type, globalFlags); | ||
|
||
function writeType(type: Type, flags: TypeFormatFlags) { | ||
const nextFlags = flags & ~TypeFormatFlags.InTypeAlias; | ||
|
||
// Write undefined/null type as any | ||
if (type.flags & TypeFlags.Intrinsic) { | ||
// Special handling for unknown / resolving types, they should show up as any and not unknown or __resolving | ||
|
@@ -2152,14 +2156,9 @@ namespace ts { | |
// The specified symbol flags need to be reinterpreted as type flags | ||
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags); | ||
} | ||
else if (!(flags & TypeFormatFlags.InTypeAlias) && type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol) { | ||
if (type.flags & TypeFlags.Anonymous || !(flags & TypeFormatFlags.UseTypeAliasValue)) { | ||
const typeArguments = type.aliasTypeArguments; | ||
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags); | ||
} | ||
else { | ||
writeUnionOrIntersectionType(<UnionOrIntersectionType>type, nextFlags); | ||
} | ||
else if (!(flags & TypeFormatFlags.InTypeAlias) && type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol && !(flags & TypeFormatFlags.UseTypeAliasValue)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again can we combine InTypeAlias and UseTypeAliasValue with | There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure I understand what you mean. 😅 I will catch you offline tmr. I think it may be better to just serialize type-alias all the time There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again can we combine InTypeAlias and UseTypeAliasValue with | |
||
const typeArguments = type.aliasTypeArguments; | ||
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags); | ||
} | ||
else if (type.flags & TypeFlags.UnionOrIntersection) { | ||
writeUnionOrIntersectionType(<UnionOrIntersectionType>type, nextFlags); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//// [declFileTypeAliasWithGeneric.ts] | ||
export type Bar<X, Y> = () => [X, Y]; | ||
export type Foo<Y> = Bar<any, Y>; | ||
export const y = (x: Foo<string>) => 1 | ||
|
||
//// [declFileTypeAliasWithGeneric.js] | ||
"use strict"; | ||
exports.y = function (x) { return 1; }; | ||
|
||
|
||
//// [declFileTypeAliasWithGeneric.d.ts] | ||
export declare type Bar<X, Y> = () => [X, Y]; | ||
export declare type Foo<Y> = Bar<any, Y>; | ||
export declare const y: (x: () => [any, string]) => number; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
=== tests/cases/compiler/declFileTypeAliasWithGeneric.ts === | ||
export type Bar<X, Y> = () => [X, Y]; | ||
>Bar : Symbol(Bar, Decl(declFileTypeAliasWithGeneric.ts, 0, 0)) | ||
>X : Symbol(X, Decl(declFileTypeAliasWithGeneric.ts, 0, 16)) | ||
>Y : Symbol(Y, Decl(declFileTypeAliasWithGeneric.ts, 0, 18)) | ||
>X : Symbol(X, Decl(declFileTypeAliasWithGeneric.ts, 0, 16)) | ||
>Y : Symbol(Y, Decl(declFileTypeAliasWithGeneric.ts, 0, 18)) | ||
|
||
export type Foo<Y> = Bar<any, Y>; | ||
>Foo : Symbol(Foo, Decl(declFileTypeAliasWithGeneric.ts, 0, 37)) | ||
>Y : Symbol(Y, Decl(declFileTypeAliasWithGeneric.ts, 1, 16)) | ||
>Bar : Symbol(Bar, Decl(declFileTypeAliasWithGeneric.ts, 0, 0)) | ||
>Y : Symbol(Y, Decl(declFileTypeAliasWithGeneric.ts, 1, 16)) | ||
|
||
export const y = (x: Foo<string>) => 1 | ||
>y : Symbol(y, Decl(declFileTypeAliasWithGeneric.ts, 2, 12)) | ||
>x : Symbol(x, Decl(declFileTypeAliasWithGeneric.ts, 2, 18)) | ||
>Foo : Symbol(Foo, Decl(declFileTypeAliasWithGeneric.ts, 0, 37)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
=== tests/cases/compiler/declFileTypeAliasWithGeneric.ts === | ||
export type Bar<X, Y> = () => [X, Y]; | ||
>Bar : Bar<X, Y> | ||
>X : X | ||
>Y : Y | ||
>X : X | ||
>Y : Y | ||
|
||
export type Foo<Y> = Bar<any, Y>; | ||
>Foo : Bar<any, Y> | ||
>Y : Y | ||
>Bar : Bar<X, Y> | ||
>Y : Y | ||
|
||
export const y = (x: Foo<string>) => 1 | ||
>y : (x: Bar<string>) => number | ||
>(x: Foo<string>) => 1 : (x: Bar<string>) => number | ||
>x : Bar<string> | ||
>Foo : Bar<any, Y> | ||
>1 : number | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// @declaration: true | ||
export type Bar<X, Y> = () => [X, Y]; | ||
export type Foo<Y> = Bar<any, Y>; | ||
export const y = (x: Foo<string>) => 1 |
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.
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.
then that will make we serialize type-alias all the time. THough we won't want to do that for quickinfo I think. because in if we want to serialize type-alias all the time, we can just remove the check completely