Skip to content

Commit 14a12d0

Browse files
gabrittoahejlsbergGabriela Araujo Britto
authored
Restore #3529 (#3640)
Co-authored-by: Anders Hejlsberg <andersh@microsoft.com> Co-authored-by: Gabriela Araujo Britto <gabrielaa@CPC-gabri-8SHBT.localdomain>
1 parent de302e0 commit 14a12d0

4 files changed

Lines changed: 11 additions & 50 deletions

File tree

internal/checker/checker.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,12 +1653,15 @@ func isES2015OrLaterConstructorName(s string) bool {
16531653
}
16541654

16551655
func (c *Checker) maybeMappedType(node *ast.Node, symbol *ast.Symbol) bool {
1656-
for ast.IsComputedPropertyName(node) || ast.IsPropertySignatureDeclaration(node) {
1656+
for {
16571657
node = node.Parent
1658+
if !(ast.IsComputedPropertyName(node) || ast.IsPropertySignatureDeclaration(node)) {
1659+
break
1660+
}
16581661
}
16591662
if ast.IsTypeLiteralNode(node) && len(node.Members()) == 1 {
16601663
t := c.getDeclaredTypeOfSymbol(symbol)
1661-
return t.flags&TypeFlagsUnion != 0 && c.allTypesAssignableToKind(t, TypeFlagsStringOrNumberLiteral)
1664+
return t.flags&TypeFlagsUnion != 0 && c.allTypesAssignableToKindEx(t, TypeFlagsStringOrNumberLiteral, true /*strict*/)
16621665
}
16631666
return false
16641667
}

testdata/baselines/reference/submodule/compiler/typeUsedAsTypeLiteralIndex.errors.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
typeUsedAsTypeLiteralIndex.ts(3,6): error TS2693: 'K' only refers to a type, but is being used as a value here.
2-
typeUsedAsTypeLiteralIndex.ts(13,6): error TS2693: 'K2' only refers to a type, but is being used as a value here.
3-
typeUsedAsTypeLiteralIndex.ts(18,6): error TS2693: 'K3' only refers to a type, but is being used as a value here.
1+
typeUsedAsTypeLiteralIndex.ts(3,6): error TS2690: 'K' only refers to a type, but is being used as a value here. Did you mean to use 'P in K'?
2+
typeUsedAsTypeLiteralIndex.ts(13,6): error TS2690: 'K2' only refers to a type, but is being used as a value here. Did you mean to use 'K in K2'?
3+
typeUsedAsTypeLiteralIndex.ts(18,6): error TS2690: 'K3' only refers to a type, but is being used as a value here. Did you mean to use 'K in K3'?
44
typeUsedAsTypeLiteralIndex.ts(23,6): error TS2693: 'K4' only refers to a type, but is being used as a value here.
55

66

@@ -9,7 +9,7 @@ typeUsedAsTypeLiteralIndex.ts(23,6): error TS2693: 'K4' only refers to a type, b
99
type T = {
1010
[K]: number; // Did you mean to use 'P in K'?
1111
~
12-
!!! error TS2693: 'K' only refers to a type, but is being used as a value here.
12+
!!! error TS2690: 'K' only refers to a type, but is being used as a value here. Did you mean to use 'P in K'?
1313
}
1414

1515
const K1 = Symbol();
@@ -21,14 +21,14 @@ typeUsedAsTypeLiteralIndex.ts(23,6): error TS2693: 'K4' only refers to a type, b
2121
type T2 = {
2222
[K2]: number; // Did you mean to use 'K in K2'?
2323
~~
24-
!!! error TS2693: 'K2' only refers to a type, but is being used as a value here.
24+
!!! error TS2690: 'K2' only refers to a type, but is being used as a value here. Did you mean to use 'K in K2'?
2525
}
2626

2727
type K3 = number | string;
2828
type T3 = {
2929
[K3]: number; // Did you mean to use 'K in K3'?
3030
~~
31-
!!! error TS2693: 'K3' only refers to a type, but is being used as a value here.
31+
!!! error TS2690: 'K3' only refers to a type, but is being used as a value here. Did you mean to use 'K in K3'?
3232
}
3333

3434
type K4 = number | string;

testdata/baselines/reference/submoduleTriaged/compiler/typeUsedAsTypeLiteralIndex.errors.txt.diff

Lines changed: 0 additions & 38 deletions
This file was deleted.

testdata/submoduleTriaged.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ compiler/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt.diff
103103
compiler/parseErrorIncorrectReturnToken.errors.txt.diff
104104
conformance/parserStatementIsNotAMemberVariableDeclaration1(alwaysstrict=true).errors.txt.diff
105105

106-
# TS2690 (with "Did you mean 'P in K'?" mapped type suggestion) changed to TS2693 (generic "refers to a type, but is being used as a value") — mapped type suggestion lost
107-
## https://github.com/microsoft/typescript-go/issues/3509
108-
compiler/typeUsedAsTypeLiteralIndex.errors.txt.diff
109-
110106
# Unicode escapes in identifier names now displayed as literal characters
111107
## https://github.com/microsoft/typescript-go/issues/3511
112108
conformance/parser.numericSeparators.decmialNegative.errors.txt.diff

0 commit comments

Comments
 (0)