Skip to content

Commit 9accee9

Browse files
committed
Add contextual type and completions for ImportCall options argument
1 parent 463138a commit 9accee9

File tree

3 files changed

+160
-4
lines changed

3 files changed

+160
-4
lines changed

src/compiler/checker.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -25558,6 +25558,12 @@ namespace ts {
2555825558
}
2555925559

2556025560
function getContextualTypeForArgumentAtIndex(callTarget: CallLikeExpression, argIndex: number): Type {
25561+
if (isImportCall(callTarget)) {
25562+
return argIndex === 0 ? stringType :
25563+
argIndex === 1 ? getGlobalImportCallOptionsType(/*reportErrors*/ false) :
25564+
anyType;
25565+
}
25566+
2556125567
// If we're already in the process of resolving the given signature, don't resolve again as
2556225568
// that could cause infinite recursion. Instead, return anySignature.
2556325569
const signature = getNodeLinks(callTarget).resolvedSignature === resolvingSignature ? resolvingSignature : getResolvedSignature(callTarget);
@@ -26018,10 +26024,6 @@ namespace ts {
2601826024
case SyntaxKind.AwaitExpression:
2601926025
return getContextualTypeForAwaitOperand(parent as AwaitExpression, contextFlags);
2602026026
case SyntaxKind.CallExpression:
26021-
if ((parent as CallExpression).expression.kind === SyntaxKind.ImportKeyword) {
26022-
return stringType;
26023-
}
26024-
/* falls through */
2602526027
case SyntaxKind.NewExpression:
2602626028
return getContextualTypeForArgument(parent as CallExpression | NewExpression, node);
2602726029
case SyntaxKind.TypeAssertionExpression:
@@ -30617,6 +30619,7 @@ namespace ts {
3061730619
if (node.arguments.length === 0) {
3061830620
return createPromiseReturnType(node, anyType);
3061930621
}
30622+
3062030623
const specifier = node.arguments[0];
3062130624
const specifierType = checkExpressionCached(specifier);
3062230625
const optionsType = node.arguments.length > 1 ? checkExpressionCached(node.arguments[1]) : undefined;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
[
2+
{
3+
"marker": {
4+
"fileName": "/tests/cases/fourslash/main.ts",
5+
"position": 24,
6+
"name": "0"
7+
},
8+
"completionList": {
9+
"isGlobalCompletion": false,
10+
"isMemberCompletion": true,
11+
"isNewIdentifierLocation": false,
12+
"entries": [
13+
{
14+
"name": "assert",
15+
"kind": "property",
16+
"kindModifiers": "declare,optional",
17+
"sortText": "12",
18+
"displayParts": [
19+
{
20+
"text": "(",
21+
"kind": "punctuation"
22+
},
23+
{
24+
"text": "property",
25+
"kind": "text"
26+
},
27+
{
28+
"text": ")",
29+
"kind": "punctuation"
30+
},
31+
{
32+
"text": " ",
33+
"kind": "space"
34+
},
35+
{
36+
"text": "ImportCallOptions",
37+
"kind": "interfaceName"
38+
},
39+
{
40+
"text": ".",
41+
"kind": "punctuation"
42+
},
43+
{
44+
"text": "assert",
45+
"kind": "propertyName"
46+
},
47+
{
48+
"text": "?",
49+
"kind": "punctuation"
50+
},
51+
{
52+
"text": ":",
53+
"kind": "punctuation"
54+
},
55+
{
56+
"text": " ",
57+
"kind": "space"
58+
},
59+
{
60+
"text": "ImportAssertions",
61+
"kind": "interfaceName"
62+
}
63+
],
64+
"documentation": []
65+
}
66+
]
67+
}
68+
},
69+
{
70+
"marker": {
71+
"fileName": "/tests/cases/fourslash/main.ts",
72+
"position": 57,
73+
"name": "1"
74+
},
75+
"completionList": {
76+
"isGlobalCompletion": false,
77+
"isMemberCompletion": true,
78+
"isNewIdentifierLocation": false,
79+
"optionalReplacementSpan": {
80+
"start": 53,
81+
"length": 4
82+
},
83+
"entries": [
84+
{
85+
"name": "assert",
86+
"kind": "property",
87+
"kindModifiers": "declare,optional",
88+
"sortText": "12",
89+
"displayParts": [
90+
{
91+
"text": "(",
92+
"kind": "punctuation"
93+
},
94+
{
95+
"text": "property",
96+
"kind": "text"
97+
},
98+
{
99+
"text": ")",
100+
"kind": "punctuation"
101+
},
102+
{
103+
"text": " ",
104+
"kind": "space"
105+
},
106+
{
107+
"text": "ImportCallOptions",
108+
"kind": "interfaceName"
109+
},
110+
{
111+
"text": ".",
112+
"kind": "punctuation"
113+
},
114+
{
115+
"text": "assert",
116+
"kind": "propertyName"
117+
},
118+
{
119+
"text": "?",
120+
"kind": "punctuation"
121+
},
122+
{
123+
"text": ":",
124+
"kind": "punctuation"
125+
},
126+
{
127+
"text": " ",
128+
"kind": "space"
129+
},
130+
{
131+
"text": "ImportAssertions",
132+
"kind": "interfaceName"
133+
}
134+
],
135+
"documentation": []
136+
}
137+
]
138+
}
139+
}
140+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @target: esnext
4+
// @module: esnext
5+
6+
// @filename: main.ts
7+
////import("./other.json", {/*0*/});
8+
////import("./other.json", { asse/*1*/});
9+
10+
// @filename: other.json
11+
////{}
12+
13+
verify.baselineCompletions();

0 commit comments

Comments
 (0)