Skip to content

Commit 4533652

Browse files
authored
Avoid check for union keys (#39314)
1 parent 0d84f21 commit 4533652

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13290,13 +13290,13 @@ namespace ts {
1329013290
&& every(symbol.declarations, d => !isFunctionLike(d) || !!(d.flags & NodeFlags.Deprecated));
1329113291
}
1329213292

13293-
function getPropertyTypeForIndexType(originalObjectType: Type, objectType: Type, indexType: Type, fullIndexType: Type, suppressNoImplicitAnyError: boolean, accessNode: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression | undefined, accessFlags: AccessFlags) {
13293+
function getPropertyTypeForIndexType(originalObjectType: Type, objectType: Type, indexType: Type, fullIndexType: Type, suppressNoImplicitAnyError: boolean, accessNode: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression | undefined, accessFlags: AccessFlags, reportDeprecated?: boolean) {
1329413294
const accessExpression = accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode : undefined;
1329513295
const propName = accessNode && isPrivateIdentifier(accessNode) ? undefined : getPropertyNameFromIndex(indexType, accessNode);
1329613296
if (propName !== undefined) {
1329713297
const prop = getPropertyOfType(objectType, propName);
1329813298
if (prop) {
13299-
if (accessNode && prop.valueDeclaration?.flags & NodeFlags.Deprecated && isUncalledFunctionReference(accessNode, prop)) {
13299+
if (reportDeprecated && accessNode && prop.valueDeclaration?.flags & NodeFlags.Deprecated && isUncalledFunctionReference(accessNode, prop)) {
1330013300
const deprecatedNode = accessExpression?.argumentExpression ?? (isIndexedAccessTypeNode(accessNode) ? accessNode.indexType : accessNode);
1330113301
errorOrSuggestion(/* isError */ false, deprecatedNode, Diagnostics._0_is_deprecated, propName as string);
1330213302
}
@@ -13666,7 +13666,7 @@ namespace ts {
1366613666
}
1366713667
return accessFlags & AccessFlags.Writing ? getIntersectionType(propTypes, aliasSymbol, aliasTypeArguments) : getUnionType(propTypes, UnionReduction.Literal, aliasSymbol, aliasTypeArguments);
1366813668
}
13669-
return getPropertyTypeForIndexType(objectType, apparentObjectType, indexType, indexType, /* supressNoImplicitAnyError */ false, accessNode, accessFlags | AccessFlags.CacheSymbol);
13669+
return getPropertyTypeForIndexType(objectType, apparentObjectType, indexType, indexType, /* supressNoImplicitAnyError */ false, accessNode, accessFlags | AccessFlags.CacheSymbol, /* reportDeprecated */ true);
1367013670
}
1367113671

1367213672
function getTypeFromIndexedAccessTypeNode(node: IndexedAccessTypeNode) {
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
///<reference path="fourslash.ts" />
2+
3+
//// interface Foo {
4+
//// /** @deprecated */
5+
//// f: number
6+
//// b: number
7+
//// /** @deprecated */
8+
//// baz: number
9+
//// }
10+
11+
//// declare const f: Foo
12+
//// f.[|f|];
13+
//// f.b;
14+
//// f.[|baz|];
15+
16+
//// const kf = 'f'
17+
//// const kb = 'b'
18+
//// declare const k: 'f' | 'b' | 'baz'
19+
//// declare const kfb: 'f' | 'b'
20+
//// declare const kfz: 'f' | 'baz'
21+
//// declare const keys: keyof Foo
22+
//// f[[|kf|]]
23+
//// f[kb]
24+
//// f[k]
25+
//// f[kfb]
26+
//// f[kfz]
27+
//// f[keys]
28+
29+
30+
const ranges = test.ranges();
31+
verify.getSuggestionDiagnostics([
32+
{
33+
message: "'f' is deprecated",
34+
code: 6385,
35+
range: ranges[0],
36+
reportsDeprecated: true,
37+
},
38+
{
39+
message: "'baz' is deprecated",
40+
code: 6385,
41+
range: ranges[1],
42+
reportsDeprecated: true,
43+
},
44+
{
45+
message: "'f' is deprecated",
46+
code: 6385,
47+
range: ranges[2],
48+
reportsDeprecated: true,
49+
}
50+
])

0 commit comments

Comments
 (0)