mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-10-29 08:56:58 +08:00
Preserve enum computed property names in declarations (microsoft/typescript-go#4852)
This commit is contained in:
1 parent
e3fddc7198
commit
3a2dcd3d30
42 files changed
+843
-45
No files matched your search
@@ -2423,7 +2423,7 @@ func (b *NodeBuilderImpl) isSingleQuotedStringNamed(d *ast.Declaration) bool {
|
||||
return name != nil && ast.IsStringLiteral(name) && name.AsStringLiteral().TokenFlags&ast.TokenFlagsSingleQuote != 0
|
||||
}
|
||||
|
||||
func (b *NodeBuilderImpl) getPropertyNameNodeForSymbol(symbol *ast.Symbol) *ast.Node {
|
||||
func (b *NodeBuilderImpl) getPropertyNameNodeForSymbol(symbol *ast.Symbol, enclosingDeclaration *ast.Node) *ast.Node {
|
||||
// For hash-private names, clone the original private identifier from the declaration
|
||||
if symbol.ValueDeclaration != nil {
|
||||
declName := symbol.ValueDeclaration.Name()
|
||||
@@ -2434,7 +2434,7 @@ func (b *NodeBuilderImpl) getPropertyNameNodeForSymbol(symbol *ast.Symbol) *ast.
|
||||
stringNamed := len(symbol.Declarations) != 0 && core.Every(symbol.Declarations, b.isStringNamed)
|
||||
singleQuote := len(symbol.Declarations) != 0 && core.Every(symbol.Declarations, b.isSingleQuotedStringNamed)
|
||||
isMethod := symbol.Flags&ast.SymbolFlagsMethod != 0
|
||||
fromNameType := b.getPropertyNameNodeForSymbolFromNameType(symbol, singleQuote, stringNamed, isMethod)
|
||||
fromNameType := b.getPropertyNameNodeForSymbolFromNameType(symbol, enclosingDeclaration, singleQuote, stringNamed, isMethod)
|
||||
if fromNameType != nil {
|
||||
return fromNameType
|
||||
}
|
||||
@@ -2452,7 +2452,7 @@ func (b *NodeBuilderImpl) getPropertyNameNodeForSymbol(symbol *ast.Symbol) *ast.
|
||||
}
|
||||
|
||||
// See getNameForSymbolFromNameType for a stringy equivalent
|
||||
func (b *NodeBuilderImpl) getPropertyNameNodeForSymbolFromNameType(symbol *ast.Symbol, singleQuote bool, stringNamed bool, isMethod bool) *ast.Node {
|
||||
func (b *NodeBuilderImpl) getPropertyNameNodeForSymbolFromNameType(symbol *ast.Symbol, enclosingDeclaration *ast.Node, singleQuote bool, stringNamed bool, isMethod bool) *ast.Node {
|
||||
if !b.ch.valueSymbolLinks.Has(symbol) {
|
||||
return nil
|
||||
}
|
||||
@@ -2460,6 +2460,24 @@ func (b *NodeBuilderImpl) getPropertyNameNodeForSymbolFromNameType(symbol *ast.S
|
||||
if nameType == nil {
|
||||
return nil
|
||||
}
|
||||
enumEnclosingDeclaration := enclosingDeclaration
|
||||
if enumEnclosingDeclaration == nil && b.ctx.enclosingFile != nil {
|
||||
enumEnclosingDeclaration = b.ctx.enclosingFile.AsNode()
|
||||
}
|
||||
if nameType.flags&TypeFlagsEnumLiteral != 0 {
|
||||
enumSymbol := nameType.symbol.Parent
|
||||
if enumSymbol == nil {
|
||||
enumSymbol = nameType.symbol
|
||||
}
|
||||
if enumEnclosingDeclaration != nil &&
|
||||
b.ch.IsSymbolAccessibleByFlags(enumSymbol, enumEnclosingDeclaration, ast.SymbolFlagsValue) {
|
||||
saveEnclosingDeclaration := b.ctx.enclosingDeclaration
|
||||
b.ctx.enclosingDeclaration = enumEnclosingDeclaration
|
||||
result := b.f.NewComputedPropertyName(b.symbolToExpression(nameType.symbol, ast.SymbolFlagsValue))
|
||||
b.ctx.enclosingDeclaration = saveEnclosingDeclaration
|
||||
return result
|
||||
}
|
||||
}
|
||||
if nameType.flags&TypeFlagsStringOrNumberLiteral != 0 {
|
||||
var name string
|
||||
switch nameType.AsLiteralType().value.(type) {
|
||||
@@ -2517,7 +2535,7 @@ func (b *NodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t
|
||||
} else {
|
||||
b.ctx.enclosingDeclaration = saveEnclosingDeclaration
|
||||
}
|
||||
propertyName := b.getPropertyNameNodeForSymbol(propertySymbol)
|
||||
propertyName := b.getPropertyNameNodeForSymbol(propertySymbol, saveEnclosingDeclaration)
|
||||
b.ctx.enclosingDeclaration = saveEnclosingDeclaration
|
||||
b.ctx.approximateLength += len(ast.SymbolName(propertySymbol)) + 1
|
||||
|
||||
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
//// [tests/cases/compiler/enumComputedPropertyDeclarationEmit.ts] ////
|
||||
|
||||
//// [enumComputedPropertyDeclarationEmit.ts]
|
||||
export enum StringEnum {
|
||||
A = "a",
|
||||
B = "not-an-identifier",
|
||||
Unused = "unused",
|
||||
}
|
||||
|
||||
export const stringRecord = {
|
||||
[StringEnum.A]: StringEnum.A,
|
||||
[StringEnum.B]: StringEnum.B,
|
||||
} as const;
|
||||
|
||||
export type StringKey = keyof typeof stringRecord;
|
||||
|
||||
export enum NumericEnum {
|
||||
Zero = 0,
|
||||
Negative = -1,
|
||||
Unused = 1,
|
||||
}
|
||||
|
||||
export const numericRecord = {
|
||||
[NumericEnum.Zero]: NumericEnum.Zero,
|
||||
[NumericEnum.Negative]: NumericEnum.Negative,
|
||||
} as const;
|
||||
|
||||
export type NumericKey = keyof typeof numericRecord;
|
||||
|
||||
type Assignability<T extends StringEnum | NumericEnum> = T;
|
||||
export type StringDemo<T extends StringKey> = Assignability<T>;
|
||||
export type NumericDemo<T extends NumericKey> = Assignability<T>;
|
||||
|
||||
export namespace Namespace {
|
||||
enum NamespaceEnum {
|
||||
A = "a",
|
||||
}
|
||||
|
||||
export const record = {
|
||||
[NamespaceEnum.A]: NamespaceEnum.A,
|
||||
} as const;
|
||||
|
||||
export type Key = keyof typeof record;
|
||||
|
||||
type NamespaceAssignability<T extends NamespaceEnum> = T;
|
||||
export type Demo<T extends Key> = NamespaceAssignability<T>;
|
||||
}
|
||||
|
||||
|
||||
//// [enumComputedPropertyDeclarationEmit.js]
|
||||
export var StringEnum;
|
||||
(function (StringEnum) {
|
||||
StringEnum["A"] = "a";
|
||||
StringEnum["B"] = "not-an-identifier";
|
||||
StringEnum["Unused"] = "unused";
|
||||
})(StringEnum || (StringEnum = {}));
|
||||
export const stringRecord = {
|
||||
[StringEnum.A]: StringEnum.A,
|
||||
[StringEnum.B]: StringEnum.B,
|
||||
};
|
||||
export var NumericEnum;
|
||||
(function (NumericEnum) {
|
||||
NumericEnum[NumericEnum["Zero"] = 0] = "Zero";
|
||||
NumericEnum[NumericEnum["Negative"] = -1] = "Negative";
|
||||
NumericEnum[NumericEnum["Unused"] = 1] = "Unused";
|
||||
})(NumericEnum || (NumericEnum = {}));
|
||||
export const numericRecord = {
|
||||
[NumericEnum.Zero]: NumericEnum.Zero,
|
||||
[NumericEnum.Negative]: NumericEnum.Negative,
|
||||
};
|
||||
export var Namespace;
|
||||
(function (Namespace) {
|
||||
let NamespaceEnum;
|
||||
(function (NamespaceEnum) {
|
||||
NamespaceEnum["A"] = "a";
|
||||
})(NamespaceEnum || (NamespaceEnum = {}));
|
||||
Namespace.record = {
|
||||
[NamespaceEnum.A]: NamespaceEnum.A,
|
||||
};
|
||||
})(Namespace || (Namespace = {}));
|
||||
|
||||
|
||||
//// [enumComputedPropertyDeclarationEmit.d.ts]
|
||||
export declare enum StringEnum {
|
||||
A = "a",
|
||||
B = "not-an-identifier",
|
||||
Unused = "unused"
|
||||
}
|
||||
export declare const stringRecord: {
|
||||
readonly [StringEnum.A]: StringEnum.A;
|
||||
readonly [StringEnum.B]: StringEnum.B;
|
||||
};
|
||||
export type StringKey = keyof typeof stringRecord;
|
||||
export declare enum NumericEnum {
|
||||
Zero = 0,
|
||||
Negative = -1,
|
||||
Unused = 1
|
||||
}
|
||||
export declare const numericRecord: {
|
||||
readonly [NumericEnum.Zero]: NumericEnum.Zero;
|
||||
readonly [NumericEnum.Negative]: NumericEnum.Negative;
|
||||
};
|
||||
export type NumericKey = keyof typeof numericRecord;
|
||||
type Assignability<T extends StringEnum | NumericEnum> = T;
|
||||
export type StringDemo<T extends StringKey> = Assignability<T>;
|
||||
export type NumericDemo<T extends NumericKey> = Assignability<T>;
|
||||
export declare namespace Namespace {
|
||||
enum NamespaceEnum {
|
||||
A = "a"
|
||||
}
|
||||
export const record: {
|
||||
readonly [NamespaceEnum.A]: NamespaceEnum;
|
||||
};
|
||||
export type Key = keyof typeof record;
|
||||
type NamespaceAssignability<T extends NamespaceEnum> = T;
|
||||
export type Demo<T extends Key> = NamespaceAssignability<T>;
|
||||
export {};
|
||||
}
|
||||
export {};
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
//// [tests/cases/compiler/enumComputedPropertyDeclarationEmit.ts] ////
|
||||
|
||||
=== enumComputedPropertyDeclarationEmit.ts ===
|
||||
export enum StringEnum {
|
||||
>StringEnum : Symbol(StringEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 0, 0))
|
||||
|
||||
A = "a",
|
||||
>A : Symbol(StringEnum.A, Decl(enumComputedPropertyDeclarationEmit.ts, 0, 24))
|
||||
|
||||
B = "not-an-identifier",
|
||||
>B : Symbol(StringEnum.B, Decl(enumComputedPropertyDeclarationEmit.ts, 1, 12))
|
||||
|
||||
Unused = "unused",
|
||||
>Unused : Symbol(StringEnum.Unused, Decl(enumComputedPropertyDeclarationEmit.ts, 2, 28))
|
||||
}
|
||||
|
||||
export const stringRecord = {
|
||||
>stringRecord : Symbol(stringRecord, Decl(enumComputedPropertyDeclarationEmit.ts, 6, 12))
|
||||
|
||||
[StringEnum.A]: StringEnum.A,
|
||||
>[StringEnum.A] : Symbol([StringEnum.A], Decl(enumComputedPropertyDeclarationEmit.ts, 6, 29))
|
||||
>StringEnum.A : Symbol(StringEnum.A, Decl(enumComputedPropertyDeclarationEmit.ts, 0, 24))
|
||||
>StringEnum : Symbol(StringEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 0, 0))
|
||||
>A : Symbol(StringEnum.A, Decl(enumComputedPropertyDeclarationEmit.ts, 0, 24))
|
||||
>StringEnum.A : Symbol(StringEnum.A, Decl(enumComputedPropertyDeclarationEmit.ts, 0, 24))
|
||||
>StringEnum : Symbol(StringEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 0, 0))
|
||||
>A : Symbol(StringEnum.A, Decl(enumComputedPropertyDeclarationEmit.ts, 0, 24))
|
||||
|
||||
[StringEnum.B]: StringEnum.B,
|
||||
>[StringEnum.B] : Symbol([StringEnum.B], Decl(enumComputedPropertyDeclarationEmit.ts, 7, 33))
|
||||
>StringEnum.B : Symbol(StringEnum.B, Decl(enumComputedPropertyDeclarationEmit.ts, 1, 12))
|
||||
>StringEnum : Symbol(StringEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 0, 0))
|
||||
>B : Symbol(StringEnum.B, Decl(enumComputedPropertyDeclarationEmit.ts, 1, 12))
|
||||
>StringEnum.B : Symbol(StringEnum.B, Decl(enumComputedPropertyDeclarationEmit.ts, 1, 12))
|
||||
>StringEnum : Symbol(StringEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 0, 0))
|
||||
>B : Symbol(StringEnum.B, Decl(enumComputedPropertyDeclarationEmit.ts, 1, 12))
|
||||
|
||||
} as const;
|
||||
>const : Symbol(const)
|
||||
|
||||
export type StringKey = keyof typeof stringRecord;
|
||||
>StringKey : Symbol(StringKey, Decl(enumComputedPropertyDeclarationEmit.ts, 9, 11))
|
||||
>stringRecord : Symbol(stringRecord, Decl(enumComputedPropertyDeclarationEmit.ts, 6, 12))
|
||||
|
||||
export enum NumericEnum {
|
||||
>NumericEnum : Symbol(NumericEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 11, 50))
|
||||
|
||||
Zero = 0,
|
||||
>Zero : Symbol(NumericEnum.Zero, Decl(enumComputedPropertyDeclarationEmit.ts, 13, 25))
|
||||
|
||||
Negative = -1,
|
||||
>Negative : Symbol(NumericEnum.Negative, Decl(enumComputedPropertyDeclarationEmit.ts, 14, 13))
|
||||
|
||||
Unused = 1,
|
||||
>Unused : Symbol(NumericEnum.Unused, Decl(enumComputedPropertyDeclarationEmit.ts, 15, 18))
|
||||
}
|
||||
|
||||
export const numericRecord = {
|
||||
>numericRecord : Symbol(numericRecord, Decl(enumComputedPropertyDeclarationEmit.ts, 19, 12))
|
||||
|
||||
[NumericEnum.Zero]: NumericEnum.Zero,
|
||||
>[NumericEnum.Zero] : Symbol([NumericEnum.Zero], Decl(enumComputedPropertyDeclarationEmit.ts, 19, 30))
|
||||
>NumericEnum.Zero : Symbol(NumericEnum.Zero, Decl(enumComputedPropertyDeclarationEmit.ts, 13, 25))
|
||||
>NumericEnum : Symbol(NumericEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 11, 50))
|
||||
>Zero : Symbol(NumericEnum.Zero, Decl(enumComputedPropertyDeclarationEmit.ts, 13, 25))
|
||||
>NumericEnum.Zero : Symbol(NumericEnum.Zero, Decl(enumComputedPropertyDeclarationEmit.ts, 13, 25))
|
||||
>NumericEnum : Symbol(NumericEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 11, 50))
|
||||
>Zero : Symbol(NumericEnum.Zero, Decl(enumComputedPropertyDeclarationEmit.ts, 13, 25))
|
||||
|
||||
[NumericEnum.Negative]: NumericEnum.Negative,
|
||||
>[NumericEnum.Negative] : Symbol([NumericEnum.Negative], Decl(enumComputedPropertyDeclarationEmit.ts, 20, 41))
|
||||
>NumericEnum.Negative : Symbol(NumericEnum.Negative, Decl(enumComputedPropertyDeclarationEmit.ts, 14, 13))
|
||||
>NumericEnum : Symbol(NumericEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 11, 50))
|
||||
>Negative : Symbol(NumericEnum.Negative, Decl(enumComputedPropertyDeclarationEmit.ts, 14, 13))
|
||||
>NumericEnum.Negative : Symbol(NumericEnum.Negative, Decl(enumComputedPropertyDeclarationEmit.ts, 14, 13))
|
||||
>NumericEnum : Symbol(NumericEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 11, 50))
|
||||
>Negative : Symbol(NumericEnum.Negative, Decl(enumComputedPropertyDeclarationEmit.ts, 14, 13))
|
||||
|
||||
} as const;
|
||||
>const : Symbol(const)
|
||||
|
||||
export type NumericKey = keyof typeof numericRecord;
|
||||
>NumericKey : Symbol(NumericKey, Decl(enumComputedPropertyDeclarationEmit.ts, 22, 11))
|
||||
>numericRecord : Symbol(numericRecord, Decl(enumComputedPropertyDeclarationEmit.ts, 19, 12))
|
||||
|
||||
type Assignability<T extends StringEnum | NumericEnum> = T;
|
||||
>Assignability : Symbol(Assignability, Decl(enumComputedPropertyDeclarationEmit.ts, 24, 52))
|
||||
>T : Symbol(T, Decl(enumComputedPropertyDeclarationEmit.ts, 26, 19))
|
||||
>StringEnum : Symbol(StringEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 0, 0))
|
||||
>NumericEnum : Symbol(NumericEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 11, 50))
|
||||
>T : Symbol(T, Decl(enumComputedPropertyDeclarationEmit.ts, 26, 19))
|
||||
|
||||
export type StringDemo<T extends StringKey> = Assignability<T>;
|
||||
>StringDemo : Symbol(StringDemo, Decl(enumComputedPropertyDeclarationEmit.ts, 26, 59))
|
||||
>T : Symbol(T, Decl(enumComputedPropertyDeclarationEmit.ts, 27, 23))
|
||||
>StringKey : Symbol(StringKey, Decl(enumComputedPropertyDeclarationEmit.ts, 9, 11))
|
||||
>Assignability : Symbol(Assignability, Decl(enumComputedPropertyDeclarationEmit.ts, 24, 52))
|
||||
>T : Symbol(T, Decl(enumComputedPropertyDeclarationEmit.ts, 27, 23))
|
||||
|
||||
export type NumericDemo<T extends NumericKey> = Assignability<T>;
|
||||
>NumericDemo : Symbol(NumericDemo, Decl(enumComputedPropertyDeclarationEmit.ts, 27, 63))
|
||||
>T : Symbol(T, Decl(enumComputedPropertyDeclarationEmit.ts, 28, 24))
|
||||
>NumericKey : Symbol(NumericKey, Decl(enumComputedPropertyDeclarationEmit.ts, 22, 11))
|
||||
>Assignability : Symbol(Assignability, Decl(enumComputedPropertyDeclarationEmit.ts, 24, 52))
|
||||
>T : Symbol(T, Decl(enumComputedPropertyDeclarationEmit.ts, 28, 24))
|
||||
|
||||
export namespace Namespace {
|
||||
>Namespace : Symbol(Namespace, Decl(enumComputedPropertyDeclarationEmit.ts, 28, 65))
|
||||
|
||||
enum NamespaceEnum {
|
||||
>NamespaceEnum : Symbol(NamespaceEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 30, 28))
|
||||
|
||||
A = "a",
|
||||
>A : Symbol(NamespaceEnum.A, Decl(enumComputedPropertyDeclarationEmit.ts, 31, 24))
|
||||
}
|
||||
|
||||
export const record = {
|
||||
>record : Symbol(record, Decl(enumComputedPropertyDeclarationEmit.ts, 35, 16))
|
||||
|
||||
[NamespaceEnum.A]: NamespaceEnum.A,
|
||||
>[NamespaceEnum.A] : Symbol([NamespaceEnum.A], Decl(enumComputedPropertyDeclarationEmit.ts, 35, 27))
|
||||
>NamespaceEnum.A : Symbol(NamespaceEnum.A, Decl(enumComputedPropertyDeclarationEmit.ts, 31, 24))
|
||||
>NamespaceEnum : Symbol(NamespaceEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 30, 28))
|
||||
>A : Symbol(NamespaceEnum.A, Decl(enumComputedPropertyDeclarationEmit.ts, 31, 24))
|
||||
>NamespaceEnum.A : Symbol(NamespaceEnum.A, Decl(enumComputedPropertyDeclarationEmit.ts, 31, 24))
|
||||
>NamespaceEnum : Symbol(NamespaceEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 30, 28))
|
||||
>A : Symbol(NamespaceEnum.A, Decl(enumComputedPropertyDeclarationEmit.ts, 31, 24))
|
||||
|
||||
} as const;
|
||||
>const : Symbol(const)
|
||||
|
||||
export type Key = keyof typeof record;
|
||||
>Key : Symbol(Key, Decl(enumComputedPropertyDeclarationEmit.ts, 37, 15))
|
||||
>record : Symbol(record, Decl(enumComputedPropertyDeclarationEmit.ts, 35, 16))
|
||||
|
||||
type NamespaceAssignability<T extends NamespaceEnum> = T;
|
||||
>NamespaceAssignability : Symbol(NamespaceAssignability, Decl(enumComputedPropertyDeclarationEmit.ts, 39, 42))
|
||||
>T : Symbol(T, Decl(enumComputedPropertyDeclarationEmit.ts, 41, 32))
|
||||
>NamespaceEnum : Symbol(NamespaceEnum, Decl(enumComputedPropertyDeclarationEmit.ts, 30, 28))
|
||||
>T : Symbol(T, Decl(enumComputedPropertyDeclarationEmit.ts, 41, 32))
|
||||
|
||||
export type Demo<T extends Key> = NamespaceAssignability<T>;
|
||||
>Demo : Symbol(Demo, Decl(enumComputedPropertyDeclarationEmit.ts, 41, 61))
|
||||
>T : Symbol(T, Decl(enumComputedPropertyDeclarationEmit.ts, 42, 21))
|
||||
>Key : Symbol(Key, Decl(enumComputedPropertyDeclarationEmit.ts, 37, 15))
|
||||
>NamespaceAssignability : Symbol(NamespaceAssignability, Decl(enumComputedPropertyDeclarationEmit.ts, 39, 42))
|
||||
>T : Symbol(T, Decl(enumComputedPropertyDeclarationEmit.ts, 42, 21))
|
||||
}
|
||||
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
//// [tests/cases/compiler/enumComputedPropertyDeclarationEmit.ts] ////
|
||||
|
||||
=== enumComputedPropertyDeclarationEmit.ts ===
|
||||
export enum StringEnum {
|
||||
>StringEnum : StringEnum
|
||||
|
||||
A = "a",
|
||||
>A : StringEnum.A
|
||||
>"a" : "a"
|
||||
|
||||
B = "not-an-identifier",
|
||||
>B : StringEnum.B
|
||||
>"not-an-identifier" : "not-an-identifier"
|
||||
|
||||
Unused = "unused",
|
||||
>Unused : StringEnum.Unused
|
||||
>"unused" : "unused"
|
||||
}
|
||||
|
||||
export const stringRecord = {
|
||||
>stringRecord : { readonly [StringEnum.A]: StringEnum.A; readonly [StringEnum.B]: StringEnum.B; }
|
||||
>{ [StringEnum.A]: StringEnum.A, [StringEnum.B]: StringEnum.B,} as const : { readonly [StringEnum.A]: StringEnum.A; readonly [StringEnum.B]: StringEnum.B; }
|
||||
>{ [StringEnum.A]: StringEnum.A, [StringEnum.B]: StringEnum.B,} : { readonly [StringEnum.A]: StringEnum.A; readonly [StringEnum.B]: StringEnum.B; }
|
||||
|
||||
[StringEnum.A]: StringEnum.A,
|
||||
>[StringEnum.A] : StringEnum.A
|
||||
>StringEnum.A : StringEnum.A
|
||||
>StringEnum : typeof StringEnum
|
||||
>A : StringEnum.A
|
||||
>StringEnum.A : StringEnum.A
|
||||
>StringEnum : typeof StringEnum
|
||||
>A : StringEnum.A
|
||||
|
||||
[StringEnum.B]: StringEnum.B,
|
||||
>[StringEnum.B] : StringEnum.B
|
||||
>StringEnum.B : StringEnum.B
|
||||
>StringEnum : typeof StringEnum
|
||||
>B : StringEnum.B
|
||||
>StringEnum.B : StringEnum.B
|
||||
>StringEnum : typeof StringEnum
|
||||
>B : StringEnum.B
|
||||
|
||||
} as const;
|
||||
|
||||
export type StringKey = keyof typeof stringRecord;
|
||||
>StringKey : StringEnum.A | StringEnum.B
|
||||
>stringRecord : { readonly [StringEnum.A]: StringEnum.A; readonly [StringEnum.B]: StringEnum.B; }
|
||||
|
||||
export enum NumericEnum {
|
||||
>NumericEnum : NumericEnum
|
||||
|
||||
Zero = 0,
|
||||
>Zero : NumericEnum.Zero
|
||||
>0 : 0
|
||||
|
||||
Negative = -1,
|
||||
>Negative : NumericEnum.Negative
|
||||
>-1 : -1
|
||||
>1 : 1
|
||||
|
||||
Unused = 1,
|
||||
>Unused : NumericEnum.Unused
|
||||
>1 : 1
|
||||
}
|
||||
|
||||
export const numericRecord = {
|
||||
>numericRecord : { readonly [NumericEnum.Zero]: NumericEnum.Zero; readonly [NumericEnum.Negative]: NumericEnum.Negative; }
|
||||
>{ [NumericEnum.Zero]: NumericEnum.Zero, [NumericEnum.Negative]: NumericEnum.Negative,} as const : { readonly [NumericEnum.Zero]: NumericEnum.Zero; readonly [NumericEnum.Negative]: NumericEnum.Negative; }
|
||||
>{ [NumericEnum.Zero]: NumericEnum.Zero, [NumericEnum.Negative]: NumericEnum.Negative,} : { readonly [NumericEnum.Zero]: NumericEnum.Zero; readonly [NumericEnum.Negative]: NumericEnum.Negative; }
|
||||
|
||||
[NumericEnum.Zero]: NumericEnum.Zero,
|
||||
>[NumericEnum.Zero] : NumericEnum.Zero
|
||||
>NumericEnum.Zero : NumericEnum.Zero
|
||||
>NumericEnum : typeof NumericEnum
|
||||
>Zero : NumericEnum.Zero
|
||||
>NumericEnum.Zero : NumericEnum.Zero
|
||||
>NumericEnum : typeof NumericEnum
|
||||
>Zero : NumericEnum.Zero
|
||||
|
||||
[NumericEnum.Negative]: NumericEnum.Negative,
|
||||
>[NumericEnum.Negative] : NumericEnum.Negative
|
||||
>NumericEnum.Negative : NumericEnum.Negative
|
||||
>NumericEnum : typeof NumericEnum
|
||||
>Negative : NumericEnum.Negative
|
||||
>NumericEnum.Negative : NumericEnum.Negative
|
||||
>NumericEnum : typeof NumericEnum
|
||||
>Negative : NumericEnum.Negative
|
||||
|
||||
} as const;
|
||||
|
||||
export type NumericKey = keyof typeof numericRecord;
|
||||
>NumericKey : NumericEnum.Zero | NumericEnum.Negative
|
||||
>numericRecord : { readonly [NumericEnum.Zero]: NumericEnum.Zero; readonly [NumericEnum.Negative]: NumericEnum.Negative; }
|
||||
|
||||
type Assignability<T extends StringEnum | NumericEnum> = T;
|
||||
>Assignability : T
|
||||
|
||||
export type StringDemo<T extends StringKey> = Assignability<T>;
|
||||
>StringDemo : T
|
||||
|
||||
export type NumericDemo<T extends NumericKey> = Assignability<T>;
|
||||
>NumericDemo : T
|
||||
|
||||
export namespace Namespace {
|
||||
>Namespace : typeof Namespace
|
||||
|
||||
enum NamespaceEnum {
|
||||
>NamespaceEnum : NamespaceEnum
|
||||
|
||||
A = "a",
|
||||
>A : NamespaceEnum.A
|
||||
>"a" : "a"
|
||||
}
|
||||
|
||||
export const record = {
|
||||
>record : { readonly [NamespaceEnum.A]: NamespaceEnum; }
|
||||
>{ [NamespaceEnum.A]: NamespaceEnum.A, } as const : { readonly [NamespaceEnum.A]: NamespaceEnum; }
|
||||
>{ [NamespaceEnum.A]: NamespaceEnum.A, } : { readonly [NamespaceEnum.A]: NamespaceEnum; }
|
||||
|
||||
[NamespaceEnum.A]: NamespaceEnum.A,
|
||||
>[NamespaceEnum.A] : NamespaceEnum
|
||||
>NamespaceEnum.A : NamespaceEnum
|
||||
>NamespaceEnum : typeof NamespaceEnum
|
||||
>A : NamespaceEnum
|
||||
>NamespaceEnum.A : NamespaceEnum
|
||||
>NamespaceEnum : typeof NamespaceEnum
|
||||
>A : NamespaceEnum
|
||||
|
||||
} as const;
|
||||
|
||||
export type Key = keyof typeof record;
|
||||
>Key : NamespaceEnum.A
|
||||
>record : { readonly [NamespaceEnum.A]: NamespaceEnum; }
|
||||
|
||||
type NamespaceAssignability<T extends NamespaceEnum> = T;
|
||||
>NamespaceAssignability : T
|
||||
|
||||
export type Demo<T extends Key> = NamespaceAssignability<T>;
|
||||
>Demo : T
|
||||
}
|
||||
|
||||
Vendored
+2
-1
@@ -40,7 +40,8 @@ declare enum EnumExample {
|
||||
}
|
||||
export default EnumExample;
|
||||
//// [index.d.ts]
|
||||
import EnumExample from './EnumExample';
|
||||
declare const _default: {
|
||||
TEST: {};
|
||||
[EnumExample.TEST]: {};
|
||||
};
|
||||
export default _default;
|
||||
Vendored
+1
-1
@@ -17,7 +17,7 @@ import EnumExample from './EnumExample';
|
||||
>EnumExample : typeof EnumExample
|
||||
|
||||
export default {
|
||||
>{ [EnumExample.TEST]: {},} : { TEST: {}; }
|
||||
>{ [EnumExample.TEST]: {},} : { [EnumExample.TEST]: {}; }
|
||||
|
||||
[EnumExample.TEST]: {},
|
||||
>[EnumExample.TEST] : {}
|
||||
|
||||
Vendored
+1
-1
@@ -15,7 +15,7 @@ export enum Enum {
|
||||
|
||||
export type Type = { x?: { [Enum.A]: 0 } };
|
||||
>Type : Type
|
||||
>x : { a: 0; } | undefined
|
||||
>x : { [Enum.A]: 0; } | undefined
|
||||
>[Enum.A] : 0
|
||||
>Enum.A : Enum.A
|
||||
>Enum : typeof Enum
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ export class A {
|
||||
>getA : () => ITest
|
||||
|
||||
return {
|
||||
>{ [TestEnum.Test1]: '123', [TestEnum.Test2]: '123', } : { "123123": string; "12312312312": string; }
|
||||
>{ [TestEnum.Test1]: '123', [TestEnum.Test2]: '123', } : { [TestEnum.Test1]: string; [TestEnum.Test2]: string; }
|
||||
|
||||
[TestEnum.Test1]: '123',
|
||||
>[TestEnum.Test1] : string
|
||||
|
||||
+4
-4
@@ -49,8 +49,8 @@ const t2 = {
|
||||
}
|
||||
|
||||
const t3 = {
|
||||
>t3 : { ENUM_KEY: number; }
|
||||
>{ [E1.A]: 1, [E1.A]: 1, // duplicate} : { ENUM_KEY: number; }
|
||||
>t3 : { [E1.A]: number; }
|
||||
>{ [E1.A]: 1, [E1.A]: 1, // duplicate} : { [E1.A]: number; }
|
||||
|
||||
[E1.A]: 1,
|
||||
>[E1.A] : number
|
||||
@@ -68,8 +68,8 @@ const t3 = {
|
||||
}
|
||||
|
||||
const t4 = {
|
||||
>t4 : { 0: number; }
|
||||
>{ [E2.B]: 1, [E2.B]: 1, // duplicate} : { 0: number; }
|
||||
>t4 : { [E2.B]: number; }
|
||||
>{ [E2.B]: 1, [E2.B]: 1, // duplicate} : { [E2.B]: number; }
|
||||
|
||||
[E2.B]: 1,
|
||||
>[E2.B] : number
|
||||
|
||||
+4
-4
@@ -61,8 +61,8 @@ const t2 = {
|
||||
}
|
||||
|
||||
const t3 = {
|
||||
>t3 : { ENUM_KEY: number; }
|
||||
>{ [keys.E1.A]: 1, [keys.E1.A]: 1, // duplicate} : { ENUM_KEY: number; }
|
||||
>t3 : { [keys.E1.A]: number; }
|
||||
>{ [keys.E1.A]: 1, [keys.E1.A]: 1, // duplicate} : { [keys.E1.A]: number; }
|
||||
|
||||
[keys.E1.A]: 1,
|
||||
>[keys.E1.A] : number
|
||||
@@ -84,8 +84,8 @@ const t3 = {
|
||||
}
|
||||
|
||||
const t4 = {
|
||||
>t4 : { 0: number; }
|
||||
>{ [keys.E2.B]: 1, [keys.E2.B]: 1, // duplicate} : { 0: number; }
|
||||
>t4 : { [keys.E2.B]: number; }
|
||||
>{ [keys.E2.B]: 1, [keys.E2.B]: 1, // duplicate} : { [keys.E2.B]: number; }
|
||||
|
||||
[keys.E2.B]: 1,
|
||||
>[keys.E2.B] : number
|
||||
|
||||
+2
-2
@@ -172,8 +172,8 @@ enum E {
|
||||
>10 : 10
|
||||
}
|
||||
export const oWithComputedProperties = {
|
||||
>oWithComputedProperties : { [x: string]: number; [x: number]: number; 1: number; 2: number; [s]: number; 10: number; }
|
||||
>{ [1]: 1, [1 + 3]: 1, [prop(2)]: 2, [s]: 1, [E.V]: 1, [str]: 0,} : { [x: string]: number; [x: number]: number; 1: number; 2: number; [s]: number; 10: number; }
|
||||
>oWithComputedProperties : { [x: string]: number; [x: number]: number; 1: number; 2: number; [s]: number; [E.V]: number; }
|
||||
>{ [1]: 1, [1 + 3]: 1, [prop(2)]: 2, [s]: 1, [E.V]: 1, [str]: 0,} : { [x: string]: number; [x: number]: number; 1: number; 2: number; [s]: number; [E.V]: number; }
|
||||
|
||||
[1]: 1,
|
||||
>[1] : number
|
||||
|
||||
+6
-6
@@ -18,7 +18,7 @@ type TestStrs = { [key in Strs]: string }
|
||||
|
||||
const x: TestStrs = {
|
||||
>x : TestStrs
|
||||
>{ [Strs.A]: 'xo', [Strs.B]: 'xe'} : { a: string; b: string; }
|
||||
>{ [Strs.A]: 'xo', [Strs.B]: 'xe'} : { [Strs.A]: string; [Strs.B]: string; }
|
||||
|
||||
[Strs.A]: 'xo',
|
||||
>[Strs.A] : string
|
||||
@@ -35,8 +35,8 @@ const x: TestStrs = {
|
||||
>'xe' : "xe"
|
||||
}
|
||||
const ux = {
|
||||
>ux : { a: string; b: string; }
|
||||
>{ [Strs.A]: 'xo', [Strs.B]: 'xe'} : { a: string; b: string; }
|
||||
>ux : { [Strs.A]: string; [Strs.B]: string; }
|
||||
>{ [Strs.A]: 'xo', [Strs.B]: 'xe'} : { [Strs.A]: string; [Strs.B]: string; }
|
||||
|
||||
[Strs.A]: 'xo',
|
||||
>[Strs.A] : string
|
||||
@@ -119,7 +119,7 @@ type TestNums = { 0: number, 1: number }
|
||||
|
||||
const n: TestNums = {
|
||||
>n : TestNums
|
||||
>{ [Nums.A]: 1, [Nums.B]: 2} : { 0: number; 1: number; }
|
||||
>{ [Nums.A]: 1, [Nums.B]: 2} : { [Nums.A]: number; [Nums.B]: number; }
|
||||
|
||||
[Nums.A]: 1,
|
||||
>[Nums.A] : number
|
||||
@@ -136,8 +136,8 @@ const n: TestNums = {
|
||||
>2 : 2
|
||||
}
|
||||
const un = {
|
||||
>un : { 0: number; 1: number; }
|
||||
>{ [Nums.A]: 3, [Nums.B]: 4} : { 0: number; 1: number; }
|
||||
>un : { [Nums.A]: number; [Nums.B]: number; }
|
||||
>{ [Nums.A]: 3, [Nums.B]: 4} : { [Nums.A]: number; [Nums.B]: number; }
|
||||
|
||||
[Nums.A]: 3,
|
||||
>[Nums.A] : number
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ type MappedPayload2 = {
|
||||
|
||||
const payloads2: MappedPayload2 = {
|
||||
>payloads2 : MappedPayload2
|
||||
>{ [Type.A]: data => { console.log(data) }} : { 0: (data: string) => void; }
|
||||
>{ [Type.A]: data => { console.log(data) }} : { [Type.A]: (data: string) => void; }
|
||||
|
||||
[Type.A]: data => { console.log(data) }
|
||||
>[Type.A] : (data: string) => void
|
||||
|
||||
+3
-3
@@ -7,12 +7,12 @@ enum E { A, B }
|
||||
>B : E.B
|
||||
|
||||
declare const m: { [K in E]: string | null };
|
||||
>m : { 0: string | null; 1: string | null; }
|
||||
>m : { [E.A]: string | null; [E.B]: string | null; }
|
||||
|
||||
if (m[E.A] !== null) {
|
||||
>m[E.A] !== null : boolean
|
||||
>m[E.A] : string | null
|
||||
>m : { 0: string | null; 1: string | null; }
|
||||
>m : { [E.A]: string | null; [E.B]: string | null; }
|
||||
>E.A : E.A
|
||||
>E : typeof E
|
||||
>A : E.A
|
||||
@@ -21,7 +21,7 @@ if (m[E.A] !== null) {
|
||||
>m[E.A].toString() : string
|
||||
>m[E.A].toString : () => string
|
||||
>m[E.A] : string
|
||||
>m : { 0: string | null; 1: string | null; }
|
||||
>m : { [E.A]: string | null; [E.B]: string | null; }
|
||||
>E.A : E.A
|
||||
>E : typeof E
|
||||
>A : E.A
|
||||
|
||||
+3
-3
@@ -14,12 +14,12 @@ enum E {
|
||||
}
|
||||
|
||||
declare const m: { [K in E]: string | null };
|
||||
>m : { A: string | null; B: string | null; }
|
||||
>m : { [E.A]: string | null; [E.B]: string | null; }
|
||||
|
||||
if (m[E.A] !== null) {
|
||||
>m[E.A] !== null : boolean
|
||||
>m[E.A] : string | null
|
||||
>m : { A: string | null; B: string | null; }
|
||||
>m : { [E.A]: string | null; [E.B]: string | null; }
|
||||
>E.A : E.A
|
||||
>E : typeof E
|
||||
>A : E.A
|
||||
@@ -28,7 +28,7 @@ if (m[E.A] !== null) {
|
||||
>m[E.A].toString() : string
|
||||
>m[E.A].toString : () => string
|
||||
>m[E.A] : string
|
||||
>m : { A: string | null; B: string | null; }
|
||||
>m : { [E.A]: string | null; [E.B]: string | null; }
|
||||
>E.A : E.A
|
||||
>E : typeof E
|
||||
>A : E.A
|
||||
|
||||
+2
-2
@@ -10,8 +10,8 @@ enum E2 { x }
|
||||
>x : E2.x
|
||||
|
||||
var o = {
|
||||
>o : { 0: number; }
|
||||
>{ [E1.x || E2.x]: 0} : { 0: number; }
|
||||
>o : { [E2.x]: number; }
|
||||
>{ [E1.x || E2.x]: 0} : { [E2.x]: number; }
|
||||
|
||||
[E1.x || E2.x]: 0
|
||||
>[E1.x || E2.x] : number
|
||||
|
||||
+2
-2
@@ -10,8 +10,8 @@ enum E2 { x }
|
||||
>x : E2.x
|
||||
|
||||
var o = {
|
||||
>o : { 0: number; }
|
||||
>{ [E1.x || E2.x]: 0} : { 0: number; }
|
||||
>o : { [E2.x]: number; }
|
||||
>{ [E1.x || E2.x]: 0} : { [E2.x]: number; }
|
||||
|
||||
[E1.x || E2.x]: 0
|
||||
>[E1.x || E2.x] : number
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ extractIndexer({
|
||||
extractIndexer({
|
||||
>extractIndexer({ [E.x]: ""}) : string
|
||||
>extractIndexer : <T>(p: { [n: number]: T; }) => T
|
||||
>{ [E.x]: ""} : { 0: string; }
|
||||
>{ [E.x]: ""} : { [E.x]: string; }
|
||||
|
||||
[E.x]: ""
|
||||
>[E.x] : string
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ extractIndexer({
|
||||
extractIndexer({
|
||||
>extractIndexer({ [E.x]: ""}) : string
|
||||
>extractIndexer : <T>(p: { [n: number]: T; }) => T
|
||||
>{ [E.x]: ""} : { 0: string; }
|
||||
>{ [E.x]: ""} : { [E.x]: string; }
|
||||
|
||||
[E.x]: ""
|
||||
>[E.x] : string
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ enum E {
|
||||
>member : E.member
|
||||
}
|
||||
var v = {
|
||||
>v : { 0: number; }
|
||||
>{ [E.member]: 0} : { 0: number; }
|
||||
>v : { [E.member]: number; }
|
||||
>{ [E.member]: 0} : { [E.member]: number; }
|
||||
|
||||
[E.member]: 0
|
||||
>[E.member] : number
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ enum E {
|
||||
>member : E.member
|
||||
}
|
||||
var v = {
|
||||
>v : { 0: number; }
|
||||
>{ [E.member]: 0} : { 0: number; }
|
||||
>v : { [E.member]: number; }
|
||||
>{ [E.member]: 0} : { [E.member]: number; }
|
||||
|
||||
[E.member]: 0
|
||||
>[E.member] : number
|
||||
|
||||
+4
-4
@@ -21,12 +21,12 @@ const { [K.a]: aVal, [K.b]: bVal } = (() => {
|
||||
>K : typeof K
|
||||
>b : K.b
|
||||
>bVal : number
|
||||
>(() => { return { [K.a]: 1, [K.b]: 1 };})() : { a: number; b: number; }
|
||||
>(() => { return { [K.a]: 1, [K.b]: 1 };}) : () => { a: number; b: number; }
|
||||
>() => { return { [K.a]: 1, [K.b]: 1 };} : () => { a: number; b: number; }
|
||||
>(() => { return { [K.a]: 1, [K.b]: 1 };})() : { [K.a]: number; [K.b]: number; }
|
||||
>(() => { return { [K.a]: 1, [K.b]: 1 };}) : () => { [K.a]: number; [K.b]: number; }
|
||||
>() => { return { [K.a]: 1, [K.b]: 1 };} : () => { [K.a]: number; [K.b]: number; }
|
||||
|
||||
return { [K.a]: 1, [K.b]: 1 };
|
||||
>{ [K.a]: 1, [K.b]: 1 } : { a: number; b: number; }
|
||||
>{ [K.a]: 1, [K.b]: 1 } : { [K.a]: number; [K.b]: number; }
|
||||
>[K.a] : number
|
||||
>K.a : K.a
|
||||
>K : typeof K
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
--- old.declarationEmitComputedNameConstEnumAlias.js
|
||||
+++ new.declarationEmitComputedNameConstEnumAlias.js
|
||||
@@= skipped -39, +39 lines =@@
|
||||
}
|
||||
export default EnumExample;
|
||||
//// [index.d.ts]
|
||||
+import EnumExample from './EnumExample';
|
||||
declare const _default: {
|
||||
- TEST: {};
|
||||
+ [EnumExample.TEST]: {};
|
||||
};
|
||||
export default _default;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
--- old.declarationEmitComputedNameConstEnumAlias.types
|
||||
+++ new.declarationEmitComputedNameConstEnumAlias.types
|
||||
@@= skipped -16, +16 lines =@@
|
||||
>EnumExample : typeof EnumExample
|
||||
|
||||
export default {
|
||||
->{ [EnumExample.TEST]: {},} : { TEST: {}; }
|
||||
+>{ [EnumExample.TEST]: {},} : { [EnumExample.TEST]: {}; }
|
||||
|
||||
[EnumExample.TEST]: {},
|
||||
>[EnumExample.TEST] : {}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
--- old.declarationEmitComputedPropertyNameEnum1.types
|
||||
+++ new.declarationEmitComputedPropertyNameEnum1.types
|
||||
@@= skipped -14, +14 lines =@@
|
||||
|
||||
export type Type = { x?: { [Enum.A]: 0 } };
|
||||
>Type : Type
|
||||
->x : { a: 0; } | undefined
|
||||
+>x : { [Enum.A]: 0; } | undefined
|
||||
>[Enum.A] : 0
|
||||
>Enum.A : Enum.A
|
||||
>Enum : typeof Enum
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
--- old.declarationEmitStringEnumUsedInNonlocalSpread.types
|
||||
+++ new.declarationEmitStringEnumUsedInNonlocalSpread.types
|
||||
@@= skipped -33, +33 lines =@@
|
||||
>getA : () => ITest
|
||||
|
||||
return {
|
||||
->{ [TestEnum.Test1]: '123', [TestEnum.Test2]: '123', } : { "123123": string; "12312312312": string; }
|
||||
+>{ [TestEnum.Test1]: '123', [TestEnum.Test2]: '123', } : { [TestEnum.Test1]: string; [TestEnum.Test2]: string; }
|
||||
|
||||
[TestEnum.Test1]: '123',
|
||||
>[TestEnum.Test1] : string
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
--- old.duplicateObjectLiteralProperty_computedName2.types
|
||||
+++ new.duplicateObjectLiteralProperty_computedName2.types
|
||||
@@= skipped -48, +48 lines =@@
|
||||
}
|
||||
|
||||
const t3 = {
|
||||
->t3 : { ENUM_KEY: number; }
|
||||
->{ [E1.A]: 1, [E1.A]: 1, // duplicate} : { ENUM_KEY: number; }
|
||||
+>t3 : { [E1.A]: number; }
|
||||
+>{ [E1.A]: 1, [E1.A]: 1, // duplicate} : { [E1.A]: number; }
|
||||
|
||||
[E1.A]: 1,
|
||||
>[E1.A] : number
|
||||
@@= skipped -19, +19 lines =@@
|
||||
}
|
||||
|
||||
const t4 = {
|
||||
->t4 : { 0: number; }
|
||||
->{ [E2.B]: 1, [E2.B]: 1, // duplicate} : { 0: number; }
|
||||
+>t4 : { [E2.B]: number; }
|
||||
+>{ [E2.B]: 1, [E2.B]: 1, // duplicate} : { [E2.B]: number; }
|
||||
|
||||
[E2.B]: 1,
|
||||
>[E2.B] : number
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
--- old.duplicateObjectLiteralProperty_computedName3.types
|
||||
+++ new.duplicateObjectLiteralProperty_computedName3.types
|
||||
@@= skipped -60, +60 lines =@@
|
||||
}
|
||||
|
||||
const t3 = {
|
||||
->t3 : { ENUM_KEY: number; }
|
||||
->{ [keys.E1.A]: 1, [keys.E1.A]: 1, // duplicate} : { ENUM_KEY: number; }
|
||||
+>t3 : { [keys.E1.A]: number; }
|
||||
+>{ [keys.E1.A]: 1, [keys.E1.A]: 1, // duplicate} : { [keys.E1.A]: number; }
|
||||
|
||||
[keys.E1.A]: 1,
|
||||
>[keys.E1.A] : number
|
||||
@@= skipped -23, +23 lines =@@
|
||||
}
|
||||
|
||||
const t4 = {
|
||||
->t4 : { 0: number; }
|
||||
->{ [keys.E2.B]: 1, [keys.E2.B]: 1, // duplicate} : { 0: number; }
|
||||
+>t4 : { [keys.E2.B]: number; }
|
||||
+>{ [keys.E2.B]: 1, [keys.E2.B]: 1, // duplicate} : { [keys.E2.B]: number; }
|
||||
|
||||
[keys.E2.B]: 1,
|
||||
>[keys.E2.B] : number
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
--- old.isolatedDeclarationErrorsObjects.types
|
||||
+++ new.isolatedDeclarationErrorsObjects.types
|
||||
@@= skipped -171, +171 lines =@@
|
||||
>10 : 10
|
||||
}
|
||||
export const oWithComputedProperties = {
|
||||
->oWithComputedProperties : { [x: string]: number; [x: number]: number; 1: number; 2: number; [s]: number; 10: number; }
|
||||
->{ [1]: 1, [1 + 3]: 1, [prop(2)]: 2, [s]: 1, [E.V]: 1, [str]: 0,} : { [x: string]: number; [x: number]: number; 1: number; 2: number; [s]: number; 10: number; }
|
||||
+>oWithComputedProperties : { [x: string]: number; [x: number]: number; 1: number; 2: number; [s]: number; [E.V]: number; }
|
||||
+>{ [1]: 1, [1 + 3]: 1, [prop(2)]: 2, [s]: 1, [E.V]: 1, [str]: 0,} : { [x: string]: number; [x: number]: number; 1: number; 2: number; [s]: number; [E.V]: number; }
|
||||
|
||||
[1]: 1,
|
||||
>[1] : number
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
--- old.objectLiteralEnumPropertyNames.types
|
||||
+++ new.objectLiteralEnumPropertyNames.types
|
||||
@@= skipped -17, +17 lines =@@
|
||||
|
||||
const x: TestStrs = {
|
||||
>x : TestStrs
|
||||
->{ [Strs.A]: 'xo', [Strs.B]: 'xe'} : { a: string; b: string; }
|
||||
+>{ [Strs.A]: 'xo', [Strs.B]: 'xe'} : { [Strs.A]: string; [Strs.B]: string; }
|
||||
|
||||
[Strs.A]: 'xo',
|
||||
>[Strs.A] : string
|
||||
@@= skipped -17, +17 lines =@@
|
||||
>'xe' : "xe"
|
||||
}
|
||||
const ux = {
|
||||
->ux : { a: string; b: string; }
|
||||
->{ [Strs.A]: 'xo', [Strs.B]: 'xe'} : { a: string; b: string; }
|
||||
+>ux : { [Strs.A]: string; [Strs.B]: string; }
|
||||
+>{ [Strs.A]: 'xo', [Strs.B]: 'xe'} : { [Strs.A]: string; [Strs.B]: string; }
|
||||
|
||||
[Strs.A]: 'xo',
|
||||
>[Strs.A] : string
|
||||
@@= skipped -84, +84 lines =@@
|
||||
|
||||
const n: TestNums = {
|
||||
>n : TestNums
|
||||
->{ [Nums.A]: 1, [Nums.B]: 2} : { 0: number; 1: number; }
|
||||
+>{ [Nums.A]: 1, [Nums.B]: 2} : { [Nums.A]: number; [Nums.B]: number; }
|
||||
|
||||
[Nums.A]: 1,
|
||||
>[Nums.A] : number
|
||||
@@= skipped -17, +17 lines =@@
|
||||
>2 : 2
|
||||
}
|
||||
const un = {
|
||||
->un : { 0: number; 1: number; }
|
||||
->{ [Nums.A]: 3, [Nums.B]: 4} : { 0: number; 1: number; }
|
||||
+>un : { [Nums.A]: number; [Nums.B]: number; }
|
||||
+>{ [Nums.A]: 3, [Nums.B]: 4} : { [Nums.A]: number; [Nums.B]: number; }
|
||||
|
||||
[Nums.A]: 3,
|
||||
>[Nums.A] : number
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
--- old.reducibleIndexedAccessTypes.types
|
||||
+++ new.reducibleIndexedAccessTypes.types
|
||||
@@= skipped -64, +64 lines =@@
|
||||
|
||||
const payloads2: MappedPayload2 = {
|
||||
>payloads2 : MappedPayload2
|
||||
->{ [Type.A]: data => { console.log(data) }} : { 0: (data: string) => void; }
|
||||
+>{ [Type.A]: data => { console.log(data) }} : { [Type.A]: (data: string) => void; }
|
||||
|
||||
[Type.A]: data => { console.log(data) }
|
||||
>[Type.A] : (data: string) => void
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
--- old.typeGuardNarrowsIndexedAccessOfKnownProperty11.types
|
||||
+++ new.typeGuardNarrowsIndexedAccessOfKnownProperty11.types
|
||||
@@= skipped -6, +6 lines =@@
|
||||
>B : E.B
|
||||
|
||||
declare const m: { [K in E]: string | null };
|
||||
->m : { 0: string | null; 1: string | null; }
|
||||
+>m : { [E.A]: string | null; [E.B]: string | null; }
|
||||
|
||||
if (m[E.A] !== null) {
|
||||
>m[E.A] !== null : boolean
|
||||
>m[E.A] : string | null
|
||||
->m : { 0: string | null; 1: string | null; }
|
||||
+>m : { [E.A]: string | null; [E.B]: string | null; }
|
||||
>E.A : E.A
|
||||
>E : typeof E
|
||||
>A : E.A
|
||||
@@= skipped -14, +14 lines =@@
|
||||
>m[E.A].toString() : string
|
||||
>m[E.A].toString : () => string
|
||||
>m[E.A] : string
|
||||
->m : { 0: string | null; 1: string | null; }
|
||||
+>m : { [E.A]: string | null; [E.B]: string | null; }
|
||||
>E.A : E.A
|
||||
>E : typeof E
|
||||
>A : E.A
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
--- old.typeGuardNarrowsIndexedAccessOfKnownProperty12.types
|
||||
+++ new.typeGuardNarrowsIndexedAccessOfKnownProperty12.types
|
||||
@@= skipped -13, +13 lines =@@
|
||||
}
|
||||
|
||||
declare const m: { [K in E]: string | null };
|
||||
->m : { A: string | null; B: string | null; }
|
||||
+>m : { [E.A]: string | null; [E.B]: string | null; }
|
||||
|
||||
if (m[E.A] !== null) {
|
||||
>m[E.A] !== null : boolean
|
||||
>m[E.A] : string | null
|
||||
->m : { A: string | null; B: string | null; }
|
||||
+>m : { [E.A]: string | null; [E.B]: string | null; }
|
||||
>E.A : E.A
|
||||
>E : typeof E
|
||||
>A : E.A
|
||||
@@= skipped -14, +14 lines =@@
|
||||
>m[E.A].toString() : string
|
||||
>m[E.A].toString : () => string
|
||||
>m[E.A] : string
|
||||
->m : { A: string | null; B: string | null; }
|
||||
+>m : { [E.A]: string | null; [E.B]: string | null; }
|
||||
>E.A : E.A
|
||||
>E : typeof E
|
||||
>A : E.A
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
--- old.computedPropertyNames47_ES5(target=es2015).types
|
||||
+++ new.computedPropertyNames47_ES5(target=es2015).types
|
||||
@@= skipped -9, +9 lines =@@
|
||||
>x : E2.x
|
||||
|
||||
var o = {
|
||||
->o : { 0: number; }
|
||||
->{ [E1.x || E2.x]: 0} : { 0: number; }
|
||||
+>o : { [E2.x]: number; }
|
||||
+>{ [E1.x || E2.x]: 0} : { [E2.x]: number; }
|
||||
|
||||
[E1.x || E2.x]: 0
|
||||
>[E1.x || E2.x] : number
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
--- old.computedPropertyNames47_ES6.types
|
||||
+++ new.computedPropertyNames47_ES6.types
|
||||
@@= skipped -9, +9 lines =@@
|
||||
>x : E2.x
|
||||
|
||||
var o = {
|
||||
->o : { 0: number; }
|
||||
->{ [E1.x || E2.x]: 0} : { 0: number; }
|
||||
+>o : { [E2.x]: number; }
|
||||
+>{ [E1.x || E2.x]: 0} : { [E2.x]: number; }
|
||||
|
||||
[E1.x || E2.x]: 0
|
||||
>[E1.x || E2.x] : number
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
--- old.computedPropertyNames48_ES5(target=es2015).types
|
||||
+++ new.computedPropertyNames48_ES5(target=es2015).types
|
||||
@@= skipped -27, +27 lines =@@
|
||||
extractIndexer({
|
||||
>extractIndexer({ [E.x]: ""}) : string
|
||||
>extractIndexer : <T>(p: { [n: number]: T; }) => T
|
||||
->{ [E.x]: ""} : { 0: string; }
|
||||
+>{ [E.x]: ""} : { [E.x]: string; }
|
||||
|
||||
[E.x]: ""
|
||||
>[E.x] : string
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
--- old.computedPropertyNames48_ES6.types
|
||||
+++ new.computedPropertyNames48_ES6.types
|
||||
@@= skipped -27, +27 lines =@@
|
||||
extractIndexer({
|
||||
>extractIndexer({ [E.x]: ""}) : string
|
||||
>extractIndexer : <T>(p: { [n: number]: T; }) => T
|
||||
->{ [E.x]: ""} : { 0: string; }
|
||||
+>{ [E.x]: ""} : { [E.x]: string; }
|
||||
|
||||
[E.x]: ""
|
||||
>[E.x] : string
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
--- old.computedPropertyNames7_ES5(target=es2015).types
|
||||
+++ new.computedPropertyNames7_ES5(target=es2015).types
|
||||
@@= skipped -7, +7 lines =@@
|
||||
>member : E.member
|
||||
}
|
||||
var v = {
|
||||
->v : { 0: number; }
|
||||
->{ [E.member]: 0} : { 0: number; }
|
||||
+>v : { [E.member]: number; }
|
||||
+>{ [E.member]: 0} : { [E.member]: number; }
|
||||
|
||||
[E.member]: 0
|
||||
>[E.member] : number
|
||||
tsc/testdata/baselines/reference/submoduleAccepted/conformance/computedPropertyNames7_ES6.types.diff
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
--- old.computedPropertyNames7_ES6.types
|
||||
+++ new.computedPropertyNames7_ES6.types
|
||||
@@= skipped -7, +7 lines =@@
|
||||
>member : E.member
|
||||
}
|
||||
var v = {
|
||||
->v : { 0: number; }
|
||||
->{ [E.member]: 0} : { 0: number; }
|
||||
+>v : { [E.member]: number; }
|
||||
+>{ [E.member]: 0} : { [E.member]: number; }
|
||||
|
||||
[E.member]: 0
|
||||
>[E.member] : number
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
--- old.destructuringObjectBindingPatternAndAssignment7(target=esnext).types
|
||||
+++ new.destructuringObjectBindingPatternAndAssignment7(target=esnext).types
|
||||
@@= skipped -20, +20 lines =@@
|
||||
>K : typeof K
|
||||
>b : K.b
|
||||
>bVal : number
|
||||
->(() => { return { [K.a]: 1, [K.b]: 1 };})() : { a: number; b: number; }
|
||||
->(() => { return { [K.a]: 1, [K.b]: 1 };}) : () => { a: number; b: number; }
|
||||
->() => { return { [K.a]: 1, [K.b]: 1 };} : () => { a: number; b: number; }
|
||||
+>(() => { return { [K.a]: 1, [K.b]: 1 };})() : { [K.a]: number; [K.b]: number; }
|
||||
+>(() => { return { [K.a]: 1, [K.b]: 1 };}) : () => { [K.a]: number; [K.b]: number; }
|
||||
+>() => { return { [K.a]: 1, [K.b]: 1 };} : () => { [K.a]: number; [K.b]: number; }
|
||||
|
||||
return { [K.a]: 1, [K.b]: 1 };
|
||||
->{ [K.a]: 1, [K.b]: 1 } : { a: number; b: number; }
|
||||
+>{ [K.a]: 1, [K.b]: 1 } : { [K.a]: number; [K.b]: number; }
|
||||
>[K.a] : number
|
||||
>K.a : K.a
|
||||
>K : typeof K
|
||||
Vendored
+20
@@ -1517,3 +1517,23 @@ compiler/destructuredDeclarationEmit.js.diff
|
||||
compiler/isolatedDeclarationErrorsExpressions.errors.txt.diff
|
||||
conformance/dependentDestructuredVariables.js.diff
|
||||
conformance/stringLiteralTypesAndTuples01.js.diff
|
||||
|
||||
## Preserve enum members in inferred computed property names ##
|
||||
compiler/declarationEmitComputedNameConstEnumAlias.js.diff
|
||||
compiler/declarationEmitComputedNameConstEnumAlias.types.diff
|
||||
compiler/declarationEmitComputedPropertyNameEnum1.types.diff
|
||||
compiler/declarationEmitStringEnumUsedInNonlocalSpread.types.diff
|
||||
compiler/duplicateObjectLiteralProperty_computedName2.types.diff
|
||||
compiler/duplicateObjectLiteralProperty_computedName3.types.diff
|
||||
compiler/isolatedDeclarationErrorsObjects.types.diff
|
||||
compiler/objectLiteralEnumPropertyNames.types.diff
|
||||
compiler/reducibleIndexedAccessTypes.types.diff
|
||||
compiler/typeGuardNarrowsIndexedAccessOfKnownProperty11.types.diff
|
||||
compiler/typeGuardNarrowsIndexedAccessOfKnownProperty12.types.diff
|
||||
conformance/computedPropertyNames47_ES5(target=es2015).types.diff
|
||||
conformance/computedPropertyNames47_ES6.types.diff
|
||||
conformance/computedPropertyNames48_ES5(target=es2015).types.diff
|
||||
conformance/computedPropertyNames48_ES6.types.diff
|
||||
conformance/computedPropertyNames7_ES5(target=es2015).types.diff
|
||||
conformance/computedPropertyNames7_ES6.types.diff
|
||||
conformance/destructuringObjectBindingPatternAndAssignment7(target=esnext).types.diff
|
||||
@@ -0,0 +1,46 @@
|
||||
// @declaration: true
|
||||
|
||||
export enum StringEnum {
|
||||
A = "a",
|
||||
B = "not-an-identifier",
|
||||
Unused = "unused",
|
||||
}
|
||||
|
||||
export const stringRecord = {
|
||||
[StringEnum.A]: StringEnum.A,
|
||||
[StringEnum.B]: StringEnum.B,
|
||||
} as const;
|
||||
|
||||
export type StringKey = keyof typeof stringRecord;
|
||||
|
||||
export enum NumericEnum {
|
||||
Zero = 0,
|
||||
Negative = -1,
|
||||
Unused = 1,
|
||||
}
|
||||
|
||||
export const numericRecord = {
|
||||
[NumericEnum.Zero]: NumericEnum.Zero,
|
||||
[NumericEnum.Negative]: NumericEnum.Negative,
|
||||
} as const;
|
||||
|
||||
export type NumericKey = keyof typeof numericRecord;
|
||||
|
||||
type Assignability<T extends StringEnum | NumericEnum> = T;
|
||||
export type StringDemo<T extends StringKey> = Assignability<T>;
|
||||
export type NumericDemo<T extends NumericKey> = Assignability<T>;
|
||||
|
||||
export namespace Namespace {
|
||||
enum NamespaceEnum {
|
||||
A = "a",
|
||||
}
|
||||
|
||||
export const record = {
|
||||
[NamespaceEnum.A]: NamespaceEnum.A,
|
||||
} as const;
|
||||
|
||||
export type Key = keyof typeof record;
|
||||
|
||||
type NamespaceAssignability<T extends NamespaceEnum> = T;
|
||||
export type Demo<T extends Key> = NamespaceAssignability<T>;
|
||||
}
|
||||
Reference in new issue
Block a user