mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Serialize type alias when type alias symbol is not accessible
This commit is contained in:
+26
-19
@@ -1744,7 +1744,15 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessibilityResult {
|
||||
/**
|
||||
* Check if the given symbol in given enclosing declaration is accessible and mark all associated alias to be visible if requested
|
||||
*
|
||||
* @param symbol a Symbol to check if accessible
|
||||
* @param enclosingDeclaration a Node containing the symbol
|
||||
* @param meaning a SymbolFlags to check if such meaning of the symbol is accessible
|
||||
* @param shouldComputeAliasToMarkVisible a boolean value to indicate whether to return aliases to be mark visible in case the symbol is accessible
|
||||
*/
|
||||
function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean): SymbolAccessibilityResult {
|
||||
if (symbol && enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)) {
|
||||
const initialSymbol = symbol;
|
||||
let meaningToLook = meaning;
|
||||
@@ -1752,7 +1760,7 @@ namespace ts {
|
||||
// Symbol is accessible if it by itself is accessible
|
||||
const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, /*useOnlyExternalAliasing*/ false);
|
||||
if (accessibleSymbolChain) {
|
||||
const hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
|
||||
const hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible);
|
||||
if (!hasAccessibleDeclarations) {
|
||||
return <SymbolAccessibilityResult>{
|
||||
accessibility: SymbolAccessibility.NotAccessible,
|
||||
@@ -1816,7 +1824,7 @@ namespace ts {
|
||||
return isAmbientModule(declaration) || (declaration.kind === SyntaxKind.SourceFile && isExternalOrCommonJsModule(<SourceFile>declaration));
|
||||
}
|
||||
|
||||
function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult {
|
||||
function hasVisibleDeclarations(symbol: Symbol, shouldComputeAliasToMarkVisible: boolean): SymbolVisibilityResult {
|
||||
let aliasesToMakeVisible: AnyImportSyntax[];
|
||||
if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) {
|
||||
return undefined;
|
||||
@@ -1832,14 +1840,16 @@ namespace ts {
|
||||
if (anyImportSyntax &&
|
||||
!(anyImportSyntax.flags & NodeFlags.Export) && // import clause without export
|
||||
isDeclarationVisible(<Declaration>anyImportSyntax.parent)) {
|
||||
getNodeLinks(declaration).isVisible = true;
|
||||
if (aliasesToMakeVisible) {
|
||||
if (!contains(aliasesToMakeVisible, anyImportSyntax)) {
|
||||
aliasesToMakeVisible.push(anyImportSyntax);
|
||||
if (shouldComputeAliasToMarkVisible) {
|
||||
getNodeLinks(declaration).isVisible = true;
|
||||
if (aliasesToMakeVisible) {
|
||||
if (!contains(aliasesToMakeVisible, anyImportSyntax)) {
|
||||
aliasesToMakeVisible.push(anyImportSyntax);
|
||||
}
|
||||
}
|
||||
else {
|
||||
aliasesToMakeVisible = [anyImportSyntax];
|
||||
}
|
||||
}
|
||||
else {
|
||||
aliasesToMakeVisible = [anyImportSyntax];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1874,7 +1884,7 @@ namespace ts {
|
||||
const symbol = resolveName(enclosingDeclaration, (<Identifier>firstIdentifier).text, meaning, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
|
||||
|
||||
// Verify if the symbol is accessible
|
||||
return (symbol && hasVisibleDeclarations(symbol)) || <SymbolVisibilityResult>{
|
||||
return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMarkVisible*/ true)) || <SymbolVisibilityResult>{
|
||||
accessibility: SymbolAccessibility.NotAccessible,
|
||||
errorSymbolName: getTextOfNode(firstIdentifier),
|
||||
errorNode: firstIdentifier
|
||||
@@ -2152,14 +2162,11 @@ 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 &&
|
||||
isSymbolAccessible(type.aliasSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) {
|
||||
// Only write out inferred type with its corresponding type-alias if type-alias is visible
|
||||
const typeArguments = type.aliasTypeArguments;
|
||||
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags);
|
||||
}
|
||||
else if (type.flags & TypeFlags.UnionOrIntersection) {
|
||||
writeUnionOrIntersectionType(<UnionOrIntersectionType>type, nextFlags);
|
||||
|
||||
@@ -306,7 +306,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function trackSymbol(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags) {
|
||||
handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning));
|
||||
handleSymbolAccessibilityError(resolver.isSymbolAccessible(symbol, enclosingDeclaration, meaning, /*shouldComputeAliasesToMakeVisible*/ true));
|
||||
recordTypeReferenceDirectivesIfNecessary(resolver.getTypeReferenceDirectivesForSymbol(symbol, meaning));
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
errorNameNode = declaration.name;
|
||||
resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue, writer);
|
||||
resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
errorNameNode = undefined;
|
||||
}
|
||||
}
|
||||
@@ -341,7 +341,7 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
errorNameNode = signature.name;
|
||||
resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue, writer);
|
||||
resolver.writeReturnTypeOfSignatureDeclaration(signature, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
errorNameNode = undefined;
|
||||
}
|
||||
}
|
||||
@@ -563,7 +563,7 @@ namespace ts {
|
||||
write(tempVarName);
|
||||
write(": ");
|
||||
writer.getSymbolAccessibilityDiagnostic = getDefaultExportAccessibilityDiagnostic;
|
||||
resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue, writer);
|
||||
resolver.writeTypeOfExpression(node.expression, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
write(";");
|
||||
writeLine();
|
||||
write(node.isExportEquals ? "export = " : "export default ");
|
||||
@@ -1025,7 +1025,7 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
writer.getSymbolAccessibilityDiagnostic = getHeritageClauseVisibilityError;
|
||||
resolver.writeBaseConstructorTypeOfClass(<ClassLikeDeclaration>enclosingDeclaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue, writer);
|
||||
resolver.writeBaseConstructorTypeOfClass(<ClassLikeDeclaration>enclosingDeclaration, enclosingDeclaration, TypeFormatFlags.UseTypeOfFunction, writer);
|
||||
}
|
||||
|
||||
function getHeritageClauseVisibilityError(symbolAccessibilityResult: SymbolAccessibilityResult): SymbolAccessibilityDiagnostic {
|
||||
|
||||
@@ -1949,7 +1949,6 @@ namespace ts {
|
||||
UseFullyQualifiedType = 0x00000080, // Write out the fully qualified type name (eg. Module.Type, instead of Type)
|
||||
InFirstTypeArgument = 0x00000100, // Writing first type argument of the instantiated type
|
||||
InTypeAlias = 0x00000200, // Writing type in type alias declaration
|
||||
UseTypeAliasValue = 0x00000400, // Serialize the type instead of using type-alias. This is needed when we emit declaration file.
|
||||
}
|
||||
|
||||
export const enum SymbolFormatFlags {
|
||||
@@ -2052,7 +2051,7 @@ namespace ts {
|
||||
writeReturnTypeOfSignatureDeclaration(signatureDeclaration: SignatureDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
writeTypeOfExpression(expr: Expression, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
writeBaseConstructorTypeOfClass(node: ClassLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter): void;
|
||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessibilityResult;
|
||||
isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult;
|
||||
isEntityNameVisible(entityName: EntityNameOrEntityNameExpression, enclosingDeclaration: Node): SymbolVisibilityResult;
|
||||
// Returns the constant value this property access resolves to, or 'undefined' for a non-constant
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
|
||||
@@ -62,21 +62,21 @@ declare function isHTMLCollection(sourceObj: any): sourceObj is HTMLCollection;
|
||||
>HTMLCollection : HTMLCollection
|
||||
|
||||
type EventTargetLike = {a: string} | HTMLCollection | NodeList;
|
||||
>EventTargetLike : EventTargetLike
|
||||
>EventTargetLike : NodeList | HTMLCollection | { a: string; }
|
||||
>a : string
|
||||
>HTMLCollection : HTMLCollection
|
||||
>NodeList : NodeList
|
||||
|
||||
var sourceObj: EventTargetLike = <any>undefined;
|
||||
>sourceObj : EventTargetLike
|
||||
>EventTargetLike : EventTargetLike
|
||||
>sourceObj : NodeList | HTMLCollection | { a: string; }
|
||||
>EventTargetLike : NodeList | HTMLCollection | { a: string; }
|
||||
><any>undefined : any
|
||||
>undefined : undefined
|
||||
|
||||
if (isNodeList(sourceObj)) {
|
||||
>isNodeList(sourceObj) : boolean
|
||||
>isNodeList : (sourceObj: any) => sourceObj is NodeList
|
||||
>sourceObj : EventTargetLike
|
||||
>sourceObj : NodeList | HTMLCollection | { a: string; }
|
||||
|
||||
sourceObj.length;
|
||||
>sourceObj.length : number
|
||||
@@ -87,7 +87,7 @@ if (isNodeList(sourceObj)) {
|
||||
if (isHTMLCollection(sourceObj)) {
|
||||
>isHTMLCollection(sourceObj) : boolean
|
||||
>isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection
|
||||
>sourceObj : EventTargetLike
|
||||
>sourceObj : NodeList | HTMLCollection | { a: string; }
|
||||
|
||||
sourceObj.length;
|
||||
>sourceObj.length : number
|
||||
@@ -99,7 +99,7 @@ if (isNodeList(sourceObj) || isHTMLCollection(sourceObj)) {
|
||||
>isNodeList(sourceObj) || isHTMLCollection(sourceObj) : boolean
|
||||
>isNodeList(sourceObj) : boolean
|
||||
>isNodeList : (sourceObj: any) => sourceObj is NodeList
|
||||
>sourceObj : EventTargetLike
|
||||
>sourceObj : NodeList | HTMLCollection | { a: string; }
|
||||
>isHTMLCollection(sourceObj) : boolean
|
||||
>isHTMLCollection : (sourceObj: any) => sourceObj is HTMLCollection
|
||||
>sourceObj : HTMLCollection | { a: string; }
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
{
|
||||
type Data = string | boolean;
|
||||
>Data : Data
|
||||
>Data : string | boolean
|
||||
|
||||
let obj: Data = true;
|
||||
>obj : Data
|
||||
>Data : Data
|
||||
>obj : string | boolean
|
||||
>Data : string | boolean
|
||||
>true : true
|
||||
}
|
||||
export { }
|
||||
|
||||
=== tests/cases/compiler/1.ts ===
|
||||
let v = "str" || true;
|
||||
>v : Data
|
||||
>"str" || true : Data
|
||||
>v : string | boolean
|
||||
>"str" || true : string | boolean
|
||||
>"str" : string
|
||||
>true : boolean
|
||||
|
||||
export { v }
|
||||
>v : Data
|
||||
>v : string | boolean
|
||||
|
||||
|
||||
@@ -2,29 +2,29 @@
|
||||
|
||||
{
|
||||
type Data = string | boolean;
|
||||
>Data : Data
|
||||
>Data : string | boolean
|
||||
|
||||
let obj: Data = true;
|
||||
>obj : Data
|
||||
>Data : Data
|
||||
>obj : string | boolean
|
||||
>Data : string | boolean
|
||||
>true : true
|
||||
}
|
||||
export { }
|
||||
|
||||
=== tests/cases/compiler/1.ts ===
|
||||
let v = "str" || true;
|
||||
>v : Data
|
||||
>"str" || true : Data
|
||||
>v : string | boolean
|
||||
>"str" || true : string | boolean
|
||||
>"str" : string
|
||||
>true : boolean
|
||||
|
||||
function bar () {
|
||||
>bar : () => Data
|
||||
>bar : () => string | boolean
|
||||
|
||||
return v;
|
||||
>v : Data
|
||||
>v : string | boolean
|
||||
}
|
||||
export { v, bar }
|
||||
>v : Data
|
||||
>bar : () => Data
|
||||
>v : string | boolean
|
||||
>bar : () => string | boolean
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
{
|
||||
type Data = string | boolean;
|
||||
>Data : Data
|
||||
>Data : string | boolean
|
||||
|
||||
let obj: Data = true;
|
||||
>obj : Data
|
||||
>Data : Data
|
||||
>obj : string | boolean
|
||||
>Data : string | boolean
|
||||
>true : true
|
||||
}
|
||||
export { }
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
//// [declarationEmitInferedTypeAlias4.ts]
|
||||
|
||||
function f<A>() {
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
var x: Foo<A[]>;
|
||||
return x;
|
||||
}
|
||||
|
||||
//// [declarationEmitInferedTypeAlias4.js]
|
||||
function f() {
|
||||
var x;
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
//// [declarationEmitInferedTypeAlias4.d.ts]
|
||||
declare function f<A>(): A[] | {
|
||||
x: A[] | any;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
=== tests/cases/compiler/declarationEmitInferedTypeAlias4.ts ===
|
||||
|
||||
function f<A>() {
|
||||
>f : Symbol(f, Decl(declarationEmitInferedTypeAlias4.ts, 0, 0))
|
||||
>A : Symbol(A, Decl(declarationEmitInferedTypeAlias4.ts, 1, 11))
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
>Foo : Symbol(Foo, Decl(declarationEmitInferedTypeAlias4.ts, 1, 17))
|
||||
>T : Symbol(T, Decl(declarationEmitInferedTypeAlias4.ts, 2, 13))
|
||||
>T : Symbol(T, Decl(declarationEmitInferedTypeAlias4.ts, 2, 13))
|
||||
>x : Symbol(x, Decl(declarationEmitInferedTypeAlias4.ts, 2, 23))
|
||||
>Foo : Symbol(Foo, Decl(declarationEmitInferedTypeAlias4.ts, 1, 17))
|
||||
>T : Symbol(T, Decl(declarationEmitInferedTypeAlias4.ts, 2, 13))
|
||||
|
||||
var x: Foo<A[]>;
|
||||
>x : Symbol(x, Decl(declarationEmitInferedTypeAlias4.ts, 3, 7))
|
||||
>Foo : Symbol(Foo, Decl(declarationEmitInferedTypeAlias4.ts, 1, 17))
|
||||
>A : Symbol(A, Decl(declarationEmitInferedTypeAlias4.ts, 1, 11))
|
||||
|
||||
return x;
|
||||
>x : Symbol(x, Decl(declarationEmitInferedTypeAlias4.ts, 3, 7))
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
=== tests/cases/compiler/declarationEmitInferedTypeAlias4.ts ===
|
||||
|
||||
function f<A>() {
|
||||
>f : <A>() => A[] | { x: A[] | any; }
|
||||
>A : A
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
>Foo : T | { x: T | any; }
|
||||
>T : T
|
||||
>T : T
|
||||
>x : T | { x: T | any; }
|
||||
>Foo : T | { x: T | any; }
|
||||
>T : T
|
||||
|
||||
var x: Foo<A[]>;
|
||||
>x : A[] | { x: A[] | any; }
|
||||
>Foo : T | { x: T | any; }
|
||||
>A : A
|
||||
|
||||
return x;
|
||||
>x : A[] | { x: A[] | any; }
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//// [tests/cases/compiler/declarationEmitInferedTypeAlias5.ts] ////
|
||||
|
||||
//// [0.ts]
|
||||
|
||||
export type Data = string | boolean;
|
||||
let obj: Data = true;
|
||||
|
||||
//// [1.ts]
|
||||
import * as Z from "./0"
|
||||
//let v2: Z.Data;
|
||||
let v = "str" || true;
|
||||
export { v }
|
||||
|
||||
//// [0.js]
|
||||
"use strict";
|
||||
var obj = true;
|
||||
//// [1.js]
|
||||
"use strict";
|
||||
//let v2: Z.Data;
|
||||
var v = "str" || true;
|
||||
exports.v = v;
|
||||
|
||||
|
||||
//// [0.d.ts]
|
||||
export declare type Data = string | boolean;
|
||||
//// [1.d.ts]
|
||||
import * as Z from "./0";
|
||||
declare let v: Z.Data;
|
||||
export { v };
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/compiler/0.ts ===
|
||||
|
||||
export type Data = string | boolean;
|
||||
>Data : Symbol(Data, Decl(0.ts, 0, 0))
|
||||
|
||||
let obj: Data = true;
|
||||
>obj : Symbol(obj, Decl(0.ts, 2, 3))
|
||||
>Data : Symbol(Data, Decl(0.ts, 0, 0))
|
||||
|
||||
=== tests/cases/compiler/1.ts ===
|
||||
import * as Z from "./0"
|
||||
>Z : Symbol(Z, Decl(1.ts, 0, 6))
|
||||
|
||||
//let v2: Z.Data;
|
||||
let v = "str" || true;
|
||||
>v : Symbol(v, Decl(1.ts, 2, 3))
|
||||
|
||||
export { v }
|
||||
>v : Symbol(v, Decl(1.ts, 3, 8))
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
=== tests/cases/compiler/0.ts ===
|
||||
|
||||
export type Data = string | boolean;
|
||||
>Data : Data
|
||||
|
||||
let obj: Data = true;
|
||||
>obj : Data
|
||||
>Data : Data
|
||||
>true : true
|
||||
|
||||
=== tests/cases/compiler/1.ts ===
|
||||
import * as Z from "./0"
|
||||
>Z : typeof Z
|
||||
|
||||
//let v2: Z.Data;
|
||||
let v = "str" || true;
|
||||
>v : Z.Data
|
||||
>"str" || true : Z.Data
|
||||
>"str" : string
|
||||
>true : boolean
|
||||
|
||||
export { v }
|
||||
>v : Z.Data
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
//// [tests/cases/compiler/declarationEmitInferedTypeAlias6.ts] ////
|
||||
|
||||
//// [0.ts]
|
||||
|
||||
{
|
||||
type Data = string | boolean;
|
||||
let obj: Data = true;
|
||||
}
|
||||
export { }
|
||||
|
||||
//// [1.ts]
|
||||
let v = "str" || true;
|
||||
export { v }
|
||||
|
||||
//// [0.js]
|
||||
"use strict";
|
||||
{
|
||||
var obj = true;
|
||||
}
|
||||
//// [1.js]
|
||||
"use strict";
|
||||
var v = "str" || true;
|
||||
exports.v = v;
|
||||
|
||||
|
||||
//// [0.d.ts]
|
||||
export { };
|
||||
//// [1.d.ts]
|
||||
declare let v: string | boolean;
|
||||
export { v };
|
||||
@@ -0,0 +1,19 @@
|
||||
=== tests/cases/compiler/0.ts ===
|
||||
|
||||
{
|
||||
type Data = string | boolean;
|
||||
>Data : Symbol(Data, Decl(0.ts, 1, 1))
|
||||
|
||||
let obj: Data = true;
|
||||
>obj : Symbol(obj, Decl(0.ts, 3, 7))
|
||||
>Data : Symbol(Data, Decl(0.ts, 1, 1))
|
||||
}
|
||||
export { }
|
||||
|
||||
=== tests/cases/compiler/1.ts ===
|
||||
let v = "str" || true;
|
||||
>v : Symbol(v, Decl(1.ts, 0, 3))
|
||||
|
||||
export { v }
|
||||
>v : Symbol(v, Decl(1.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
=== tests/cases/compiler/0.ts ===
|
||||
|
||||
{
|
||||
type Data = string | boolean;
|
||||
>Data : string | boolean
|
||||
|
||||
let obj: Data = true;
|
||||
>obj : string | boolean
|
||||
>Data : string | boolean
|
||||
>true : true
|
||||
}
|
||||
export { }
|
||||
|
||||
=== tests/cases/compiler/1.ts ===
|
||||
let v = "str" || true;
|
||||
>v : string | boolean
|
||||
>"str" || true : string | boolean
|
||||
>"str" : string
|
||||
>true : boolean
|
||||
|
||||
export { v }
|
||||
>v : string | boolean
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
//// [tests/cases/compiler/declarationEmitInferedTypeAlias7.ts] ////
|
||||
|
||||
//// [0.ts]
|
||||
|
||||
export type Data = string | boolean;
|
||||
let obj: Data = true;
|
||||
|
||||
//// [1.ts]
|
||||
let v = "str" || true;
|
||||
export { v }
|
||||
|
||||
//// [0.js]
|
||||
"use strict";
|
||||
var obj = true;
|
||||
//// [1.js]
|
||||
"use strict";
|
||||
var v = "str" || true;
|
||||
exports.v = v;
|
||||
|
||||
|
||||
//// [0.d.ts]
|
||||
export declare type Data = string | boolean;
|
||||
//// [1.d.ts]
|
||||
declare let v: string | boolean;
|
||||
export { v };
|
||||
@@ -0,0 +1,16 @@
|
||||
=== tests/cases/compiler/0.ts ===
|
||||
|
||||
export type Data = string | boolean;
|
||||
>Data : Symbol(Data, Decl(0.ts, 0, 0))
|
||||
|
||||
let obj: Data = true;
|
||||
>obj : Symbol(obj, Decl(0.ts, 2, 3))
|
||||
>Data : Symbol(Data, Decl(0.ts, 0, 0))
|
||||
|
||||
=== tests/cases/compiler/1.ts ===
|
||||
let v = "str" || true;
|
||||
>v : Symbol(v, Decl(1.ts, 0, 3))
|
||||
|
||||
export { v }
|
||||
>v : Symbol(v, Decl(1.ts, 1, 8))
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/compiler/0.ts ===
|
||||
|
||||
export type Data = string | boolean;
|
||||
>Data : Data
|
||||
|
||||
let obj: Data = true;
|
||||
>obj : Data
|
||||
>Data : Data
|
||||
>true : true
|
||||
|
||||
=== tests/cases/compiler/1.ts ===
|
||||
let v = "str" || true;
|
||||
>v : string | boolean
|
||||
>"str" || true : string | boolean
|
||||
>"str" : string
|
||||
>true : boolean
|
||||
|
||||
export { v }
|
||||
>v : string | boolean
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
//// [declarationEmitInferedTypeAlias8.ts]
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
var x: Foo<number[]>;
|
||||
|
||||
function returnSomeGlobalValue() {
|
||||
return x;
|
||||
}
|
||||
|
||||
//// [declarationEmitInferedTypeAlias8.js]
|
||||
var x;
|
||||
function returnSomeGlobalValue() {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
//// [declarationEmitInferedTypeAlias8.d.ts]
|
||||
declare type Foo<T> = T | {
|
||||
x: Foo<T>;
|
||||
};
|
||||
declare var x: Foo<number[]>;
|
||||
declare function returnSomeGlobalValue(): Foo<number[]>;
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/compiler/declarationEmitInferedTypeAlias8.ts ===
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
>Foo : Symbol(Foo, Decl(declarationEmitInferedTypeAlias8.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(declarationEmitInferedTypeAlias8.ts, 1, 9))
|
||||
>T : Symbol(T, Decl(declarationEmitInferedTypeAlias8.ts, 1, 9))
|
||||
>x : Symbol(x, Decl(declarationEmitInferedTypeAlias8.ts, 1, 19))
|
||||
>Foo : Symbol(Foo, Decl(declarationEmitInferedTypeAlias8.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(declarationEmitInferedTypeAlias8.ts, 1, 9))
|
||||
|
||||
var x: Foo<number[]>;
|
||||
>x : Symbol(x, Decl(declarationEmitInferedTypeAlias8.ts, 2, 3))
|
||||
>Foo : Symbol(Foo, Decl(declarationEmitInferedTypeAlias8.ts, 0, 0))
|
||||
|
||||
function returnSomeGlobalValue() {
|
||||
>returnSomeGlobalValue : Symbol(returnSomeGlobalValue, Decl(declarationEmitInferedTypeAlias8.ts, 2, 21))
|
||||
|
||||
return x;
|
||||
>x : Symbol(x, Decl(declarationEmitInferedTypeAlias8.ts, 2, 3))
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/compiler/declarationEmitInferedTypeAlias8.ts ===
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
>Foo : Foo<T>
|
||||
>T : T
|
||||
>T : T
|
||||
>x : Foo<T>
|
||||
>Foo : Foo<T>
|
||||
>T : T
|
||||
|
||||
var x: Foo<number[]>;
|
||||
>x : Foo<number[]>
|
||||
>Foo : Foo<T>
|
||||
|
||||
function returnSomeGlobalValue() {
|
||||
>returnSomeGlobalValue : () => Foo<number[]>
|
||||
|
||||
return x;
|
||||
>x : Foo<number[]>
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
//// [declarationEmitInferedTypeAlias9.ts]
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
var x: Foo<number[]>;
|
||||
|
||||
export function returnSomeGlobalValue() {
|
||||
return x;
|
||||
}
|
||||
|
||||
//// [declarationEmitInferedTypeAlias9.js]
|
||||
"use strict";
|
||||
var x;
|
||||
function returnSomeGlobalValue() {
|
||||
return x;
|
||||
}
|
||||
exports.returnSomeGlobalValue = returnSomeGlobalValue;
|
||||
|
||||
|
||||
//// [declarationEmitInferedTypeAlias9.d.ts]
|
||||
export declare function returnSomeGlobalValue(): number[] | {
|
||||
x: number[] | any;
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/compiler/declarationEmitInferedTypeAlias9.ts ===
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
>Foo : Symbol(Foo, Decl(declarationEmitInferedTypeAlias9.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(declarationEmitInferedTypeAlias9.ts, 1, 9))
|
||||
>T : Symbol(T, Decl(declarationEmitInferedTypeAlias9.ts, 1, 9))
|
||||
>x : Symbol(x, Decl(declarationEmitInferedTypeAlias9.ts, 1, 19))
|
||||
>Foo : Symbol(Foo, Decl(declarationEmitInferedTypeAlias9.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(declarationEmitInferedTypeAlias9.ts, 1, 9))
|
||||
|
||||
var x: Foo<number[]>;
|
||||
>x : Symbol(x, Decl(declarationEmitInferedTypeAlias9.ts, 2, 3))
|
||||
>Foo : Symbol(Foo, Decl(declarationEmitInferedTypeAlias9.ts, 0, 0))
|
||||
|
||||
export function returnSomeGlobalValue() {
|
||||
>returnSomeGlobalValue : Symbol(returnSomeGlobalValue, Decl(declarationEmitInferedTypeAlias9.ts, 2, 21))
|
||||
|
||||
return x;
|
||||
>x : Symbol(x, Decl(declarationEmitInferedTypeAlias9.ts, 2, 3))
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
=== tests/cases/compiler/declarationEmitInferedTypeAlias9.ts ===
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
>Foo : T | { x: T | any; }
|
||||
>T : T
|
||||
>T : T
|
||||
>x : T | { x: T | any; }
|
||||
>Foo : T | { x: T | any; }
|
||||
>T : T
|
||||
|
||||
var x: Foo<number[]>;
|
||||
>x : number[] | { x: number[] | any; }
|
||||
>Foo : T | { x: T | any; }
|
||||
|
||||
export function returnSomeGlobalValue() {
|
||||
>returnSomeGlobalValue : () => number[] | { x: number[] | any; }
|
||||
|
||||
return x;
|
||||
>x : number[] | { x: number[] | any; }
|
||||
}
|
||||
@@ -215,60 +215,60 @@ p.tag = "test";
|
||||
>"test" : string
|
||||
|
||||
function f<A>() {
|
||||
>f : <A>() => Foo<A[]>
|
||||
>f : <A>() => A[] | { x: A[] | any; }
|
||||
>A : A
|
||||
|
||||
type Foo<T> = T | { x: Foo<T> };
|
||||
>Foo : Foo<T>
|
||||
>Foo : T | { x: T | any; }
|
||||
>T : T
|
||||
>T : T
|
||||
>x : Foo<T>
|
||||
>Foo : Foo<T>
|
||||
>x : T | { x: T | any; }
|
||||
>Foo : T | { x: T | any; }
|
||||
>T : T
|
||||
|
||||
var x: Foo<A[]>;
|
||||
>x : Foo<A[]>
|
||||
>Foo : Foo<T>
|
||||
>x : A[] | { x: A[] | any; }
|
||||
>Foo : T | { x: T | any; }
|
||||
>A : A
|
||||
|
||||
return x;
|
||||
>x : Foo<A[]>
|
||||
>x : A[] | { x: A[] | any; }
|
||||
}
|
||||
|
||||
function g<B>() {
|
||||
>g : <B>() => Bar<B[]>
|
||||
>g : <B>() => B[] | { x: B[] | any; }
|
||||
>B : B
|
||||
|
||||
type Bar<U> = U | { x: Bar<U> };
|
||||
>Bar : Bar<U>
|
||||
>Bar : U | { x: U | any; }
|
||||
>U : U
|
||||
>U : U
|
||||
>x : Bar<U>
|
||||
>Bar : Bar<U>
|
||||
>x : U | { x: U | any; }
|
||||
>Bar : U | { x: U | any; }
|
||||
>U : U
|
||||
|
||||
var x: Bar<B[]>;
|
||||
>x : Bar<B[]>
|
||||
>Bar : Bar<U>
|
||||
>x : B[] | { x: B[] | any; }
|
||||
>Bar : U | { x: U | any; }
|
||||
>B : B
|
||||
|
||||
return x;
|
||||
>x : Bar<B[]>
|
||||
>x : B[] | { x: B[] | any; }
|
||||
}
|
||||
|
||||
// Deeply instantiated generics
|
||||
var a = f<string>();
|
||||
>a : Foo<string>
|
||||
>f<string>() : Foo<string>
|
||||
>f : <A>() => Foo<A[]>
|
||||
>a : string[] | { x: string[] | any; }
|
||||
>f<string>() : string[] | { x: string[] | any; }
|
||||
>f : <A>() => A[] | { x: A[] | any; }
|
||||
|
||||
var b = g<string>();
|
||||
>b : Bar<string>
|
||||
>g<string>() : Bar<string>
|
||||
>g : <B>() => Bar<B[]>
|
||||
>b : string[] | { x: string[] | any; }
|
||||
>g<string>() : string[] | { x: string[] | any; }
|
||||
>g : <B>() => B[] | { x: B[] | any; }
|
||||
|
||||
a = b;
|
||||
>a = b : Bar<string>
|
||||
>a : Foo<string>
|
||||
>b : Bar<string>
|
||||
>a = b : string[] | { x: string[] | any; }
|
||||
>a : string[] | { x: string[] | any; }
|
||||
>b : string[] | { x: string[] | any; }
|
||||
|
||||
|
||||
@@ -38,5 +38,5 @@ function rawr(dino) {
|
||||
//// [stringLiteralTypesAndTuples01.d.ts]
|
||||
declare let hello: string, brave: string, newish: string, world: string;
|
||||
declare type RexOrRaptor = "t-rex" | "raptor";
|
||||
declare let im: "I'm", a: "a", dinosaur: "t-rex" | "raptor";
|
||||
declare let im: "I'm", a: "a", dinosaur: RexOrRaptor;
|
||||
declare function rawr(dino: RexOrRaptor): string;
|
||||
|
||||
@@ -109,6 +109,6 @@ declare const boolean: "boolean";
|
||||
declare const stringOrNumber: "string" | "number";
|
||||
declare const stringOrBoolean: "string" | "boolean";
|
||||
declare const booleanOrNumber: "number" | "boolean";
|
||||
declare const stringOrBooleanOrNumber: "string" | "number" | "boolean";
|
||||
declare const stringOrBooleanOrNumber: PrimitiveName;
|
||||
declare namespace Consts2 {
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
// used in a declaration
|
||||
type handler1 = () => void;
|
||||
>handler1 : handler1
|
||||
>handler1 : () => void
|
||||
|
||||
export interface I1 {
|
||||
>I1 : I1
|
||||
|
||||
getHandler: handler1;
|
||||
>getHandler : handler1
|
||||
>handler1 : handler1
|
||||
>getHandler : () => void
|
||||
>handler1 : () => void
|
||||
}
|
||||
|
||||
// exported
|
||||
@@ -18,12 +18,12 @@ export type handler2 = () => void;
|
||||
|
||||
// used in extends clause
|
||||
type handler3 = () => void;
|
||||
>handler3 : handler3
|
||||
>handler3 : () => void
|
||||
|
||||
export interface I3<T extends handler3> {
|
||||
>I3 : I3<T>
|
||||
>T : T
|
||||
>handler3 : handler3
|
||||
>handler3 : () => void
|
||||
|
||||
getHandler: T;
|
||||
>getHandler : T
|
||||
@@ -32,32 +32,32 @@ export interface I3<T extends handler3> {
|
||||
|
||||
// used in another type alias declaration
|
||||
type handler4 = () => void;
|
||||
>handler4 : handler4
|
||||
>handler4 : () => void
|
||||
|
||||
type handler5 = handler4 | (()=>number);
|
||||
>handler5 : handler5
|
||||
>handler4 : handler4
|
||||
>handler5 : (() => void) | (() => number)
|
||||
>handler4 : () => void
|
||||
|
||||
var x: handler5;
|
||||
>x : handler5
|
||||
>handler5 : handler5
|
||||
>x : (() => void) | (() => number)
|
||||
>handler5 : (() => void) | (() => number)
|
||||
|
||||
x();
|
||||
>x() : number | void
|
||||
>x : handler5
|
||||
>x : (() => void) | (() => number)
|
||||
|
||||
// used as type argument
|
||||
type handler6 = () => void;
|
||||
>handler6 : handler6
|
||||
>handler6 : () => void
|
||||
|
||||
var y: Array<handler6>;
|
||||
>y : handler6[]
|
||||
>y : (() => void)[]
|
||||
>Array : T[]
|
||||
>handler6 : handler6
|
||||
>handler6 : () => void
|
||||
|
||||
y[0]();
|
||||
>y[0]() : void
|
||||
>y[0] : handler6
|
||||
>y : handler6[]
|
||||
>y[0] : () => void
|
||||
>y : (() => void)[]
|
||||
>0 : number
|
||||
|
||||
|
||||
Reference in New Issue
Block a user