We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 6bbacb6 commit 80a7716Copy full SHA for 80a7716
5 files changed
src/compiler/checker.ts
@@ -12744,9 +12744,11 @@ namespace ts {
12744
if (declaration.type) {
12745
return getTypeFromTypeNode(declaration.type);
12746
}
12747
- const jsDocType = isInJavaScriptFile(declaration) && getTypeForDeclarationFromJSDocComment(declaration);
12748
- if (jsDocType) {
12749
- return jsDocType;
+ if (isInJavaScriptFile(declaration)) {
+ const jsDocType = getTypeForDeclarationFromJSDocComment(declaration);
+ if (jsDocType) {
12750
+ return jsDocType;
12751
+ }
12752
12753
if (declaration.kind === SyntaxKind.Parameter) {
12754
const type = getContextuallyTypedParameterType(<ParameterDeclaration>declaration);
src/compiler/utilities.ts
@@ -2625,13 +2625,11 @@ namespace ts {
2625
if (accessor && accessor.parameters.length > 0) {
2626
const hasThis = accessor.parameters.length === 2 && parameterIsThisKeyword(accessor.parameters[0]);
2627
const parameter = accessor.parameters[hasThis ? 1 : 0];
2628
- if (parameter) {
2629
- if (parameter.type) {
2630
- return parameter.type;
2631
- }
2632
- if (includeJSDocType && parameter.flags & NodeFlags.JavaScriptFile) {
2633
- return getJSDocType(parameter);
2634
+ if (parameter.type) {
+ return parameter.type;
+ if (includeJSDocType && parameter.flags & NodeFlags.JavaScriptFile) {
+ return getJSDocType(parameter);
2635
2636
2637
tests/baselines/reference/contextualTypeFromJSDoc.symbols
@@ -10,3 +10,39 @@ const arr = [
10
>y : Symbol(y, Decl(index.js, 3, 11))
11
12
];
13
+
14
+/** @return {function(): Array<[string, {x?:number, y?:number}]>} */
15
+function f() {
16
+>f : Symbol(f, Decl(index.js, 4, 2))
17
18
+ return [
19
+ ['a', { x: 1 }],
20
+>x : Symbol(x, Decl(index.js, 9, 15))
21
22
+ ['b', { y: 2 }]
23
+>y : Symbol(y, Decl(index.js, 10, 15))
24
25
+ ];
26
+}
27
28
+class C {
29
+>C : Symbol(C, Decl(index.js, 12, 1))
30
31
+ /** @param {function(): Array<[string, {x?:number, y?:number}]>} value */
32
+ set x(value) { }
33
+>x : Symbol(C.x, Decl(index.js, 14, 9))
34
+>value : Symbol(value, Decl(index.js, 16, 10))
35
36
+ get () {
37
+>get : Symbol(C.get, Decl(index.js, 16, 20))
38
39
40
41
+>x : Symbol(x, Decl(index.js, 19, 19))
42
43
44
+>y : Symbol(y, Decl(index.js, 20, 19))
45
46
47
48
tests/baselines/reference/contextualTypeFromJSDoc.types
@@ -19,3 +19,59 @@ const arr = [
>2 : 2
+>f : () => () => [string, { x?: number; y?: number; }][]
+>[ ['a', { x: 1 }], ['b', { y: 2 }] ] : ((string | { [x: string]: any; x: number; })[] | (string | { [x: string]: any; y: number; })[])[]
+>['a', { x: 1 }] : (string | { [x: string]: any; x: number; })[]
+>'a' : "a"
+>{ x: 1 } : { [x: string]: any; x: number; }
+>x : number
+>1 : 1
+>['b', { y: 2 }] : (string | { [x: string]: any; y: number; })[]
+>'b' : "b"
+>{ y: 2 } : { [x: string]: any; y: number; }
+>y : number
+>2 : 2
+>C : C
49
50
51
52
+>x : any
53
+>value : () => [string, { x?: number; y?: number; }][]
54
55
56
+>get : () => ((string | { [x: string]: any; x: number; })[] | (string | { [x: string]: any; y: number; })[])[]
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
tests/cases/conformance/types/contextualTypes/jsdoc/contextualTypeFromJSDoc.ts
@@ -2,9 +2,29 @@
2
// @checkJs: true
3
// @noEmit: true
4
// @filename: index.js
5
+// @target: esnext
6
7
/** @type {Array<[string, {x?:number, y?:number}]>} */
8
const arr = [
9
['a', { x: 1 }],
['b', { y: 2 }]
-];
+];
0 commit comments