Skip to content

Commit d63cbd2

Browse files
authored
Fix typedef alias lookup (#1282)
1 parent d148ed8 commit d63cbd2

File tree

58 files changed

+281
-913
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+281
-913
lines changed

internal/checker/checker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22640,9 +22640,9 @@ func (c *Checker) getAliasForTypeNode(node *ast.Node) *TypeAlias {
2264022640
}
2264122641

2264222642
func (c *Checker) getAliasSymbolForTypeNode(node *ast.Node) *ast.Symbol {
22643-
host := node.Parent
22643+
host := ast.GetEffectiveTypeParent(node.Parent)
2264422644
for ast.IsParenthesizedTypeNode(host) || ast.IsTypeOperatorNode(host) && host.AsTypeOperatorNode().Operator == ast.KindReadonlyKeyword {
22645-
host = host.Parent
22645+
host = ast.GetEffectiveTypeParent(host.Parent)
2264622646
}
2264722647
if isTypeAlias(host) {
2264822648
return c.getSymbolOfDeclaration(host)

internal/parser/reparser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (p *Parser) gatherTypeParameters(j *ast.Node, tagWithTypeParameters *ast.No
227227
reparse := tp
228228
if constraint != nil && firstTypeParameter {
229229
reparse = p.factory.NewTypeParameterDeclaration(tp.Modifiers(), tp.Name(), nil, tp.AsTypeParameter().DefaultType)
230-
reparse.AsTypeParameter().Constraint = setHost(constraint, host)
230+
reparse.AsTypeParameter().Constraint = setHost(constraint, reparse)
231231
reparse.Loc = tp.Loc
232232
}
233233
if tag.AsJSDocTemplateTag().Host == nil {

testdata/baselines/reference/submodule/compiler/checkJsTypeDefNoUnusedLocalMarked.types

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ export = Foo;
2424
/** @typedef {(foo: Foo) => string} FooFun */
2525

2626
module.exports = /** @type {FooFun} */(void 0);
27-
>module.exports = /** @type {FooFun} */(void 0) : (foo: typeof import("./file")) => string
28-
>module.exports : (foo: typeof import("./file")) => string
29-
>module : { "export=": (foo: typeof import("./file")) => string; }
30-
>exports : (foo: typeof import("./file")) => string
31-
>(void 0) : (foo: typeof import("./file")) => string
27+
>module.exports = /** @type {FooFun} */(void 0) : FooFun
28+
>module.exports : FooFun
29+
>module : { "export=": FooFun; }
30+
>exports : FooFun
31+
>(void 0) : FooFun
3232
>void 0 : undefined
3333
>0 : 0
3434

testdata/baselines/reference/submodule/compiler/contextuallyTypedParametersOptionalInJSDoc.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function acceptNum(num) {}
1515

1616
/** @type {Fn} */
1717
const fn1 =
18-
>fn1 : (a: string, b: number) => void
18+
>fn1 : Fn
1919

2020
/**
2121
* @param [b]
@@ -46,7 +46,7 @@ const fn1 =
4646

4747
/** @type {Fn} */
4848
const fn2 =
49-
>fn2 : (a: string, b: number) => void
49+
>fn2 : Fn
5050

5151
/**
5252
* @param {number} [b]

testdata/baselines/reference/submodule/compiler/expandoFunctionContextualTypesJs.types

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
* @type {StatelessComponent<MyComponentProps>}
1212
*/
1313
const MyComponent = () => /* @type {any} */(null);
14-
>MyComponent : { (): any; defaultProps?: Partial<{ color: "blue" | "red"; }>; }
14+
>MyComponent : StatelessComponent<MyComponentProps>
1515
>() => /* @type {any} */(null) : { (): any; defaultProps: { color: "red"; }; }
1616
>(null) : null
1717

1818
MyComponent.defaultProps = {
1919
>MyComponent.defaultProps = { color: "red"} : { color: "red"; }
20-
>MyComponent.defaultProps : Partial<{ color: "blue" | "red"; }>
21-
>MyComponent : { (): any; defaultProps?: Partial<{ color: "blue" | "red"; }>; }
22-
>defaultProps : Partial<{ color: "blue" | "red"; }>
20+
>MyComponent.defaultProps : Partial<MyComponentProps>
21+
>MyComponent : StatelessComponent<MyComponentProps>
22+
>defaultProps : Partial<MyComponentProps>
2323
>{ color: "red"} : { color: "red"; }
2424

2525
color: "red"
@@ -29,17 +29,17 @@ MyComponent.defaultProps = {
2929
};
3030

3131
const MyComponent2 = () => null;
32-
>MyComponent2 : { (): any; defaultProps: { color: "blue" | "red"; }; }
33-
>() => null : { (): any; defaultProps: { color: "blue" | "red"; }; }
32+
>MyComponent2 : { (): any; defaultProps: MyComponentProps; }
33+
>() => null : { (): any; defaultProps: MyComponentProps; }
3434

3535
/**
3636
* @type {MyComponentProps}
3737
*/
3838
MyComponent2.defaultProps = {
3939
>MyComponent2.defaultProps = { color: "red"} : { color: "red"; }
40-
>MyComponent2.defaultProps : { color: "blue" | "red"; }
41-
>MyComponent2 : { (): any; defaultProps: { color: "blue" | "red"; }; }
42-
>defaultProps : { color: "blue" | "red"; }
40+
>MyComponent2.defaultProps : MyComponentProps
41+
>MyComponent2 : { (): any; defaultProps: MyComponentProps; }
42+
>defaultProps : MyComponentProps
4343
>{ color: "red"} : { color: "red"; }
4444

4545
color: "red"
@@ -51,16 +51,16 @@ MyComponent2.defaultProps = {
5151
* @type {StatelessComponent<MyComponentProps>}
5252
*/
5353
const check = MyComponent2;
54-
>check : { (): any; defaultProps?: Partial<{ color: "blue" | "red"; }>; }
55-
>MyComponent2 : { (): any; defaultProps: { color: "blue" | "red"; }; }
54+
>check : StatelessComponent<MyComponentProps>
55+
>MyComponent2 : { (): any; defaultProps: MyComponentProps; }
5656

5757
/**
5858
*
5959
* @param {{ props: MyComponentProps }} p
6060
*/
6161
function expectLiteral(p) {}
62-
>expectLiteral : (p: { props: { color: "blue" | "red"; }; }) => void
63-
>p : { props: { color: "blue" | "red"; }; }
62+
>expectLiteral : (p: { props: MyComponentProps; }) => void
63+
>p : { props: MyComponentProps; }
6464

6565
function foo() {
6666
>foo : () => void
@@ -79,7 +79,7 @@ function foo() {
7979

8080
expectLiteral(this);
8181
>expectLiteral(this) : void
82-
>expectLiteral : (p: { props: { color: "blue" | "red"; }; }) => void
82+
>expectLiteral : (p: { props: MyComponentProps; }) => void
8383
>this : any
8484
}
8585

@@ -88,9 +88,9 @@ function foo() {
8888
*/
8989
module.exports = {
9090
>module.exports = { color: "red"} : { color: "red"; }
91-
>module.exports : { color: "blue" | "red"; }
92-
>module : { "export=": { color: "blue" | "red"; }; }
93-
>exports : { color: "blue" | "red"; }
91+
>module.exports : MyComponentProps
92+
>module : { "export=": MyComponentProps; }
93+
>exports : MyComponentProps
9494
>{ color: "red"} : { color: "red"; }
9595

9696
color: "red"
@@ -100,10 +100,10 @@ module.exports = {
100100

101101
expectLiteral({ props: module.exports });
102102
>expectLiteral({ props: module.exports }) : void
103-
>expectLiteral : (p: { props: { color: "blue" | "red"; }; }) => void
104-
>{ props: module.exports } : { props: { color: "blue" | "red"; }; }
105-
>props : { color: "blue" | "red"; }
106-
>module.exports : { color: "blue" | "red"; }
107-
>module : { "export=": { color: "blue" | "red"; }; }
108-
>exports : { color: "blue" | "red"; }
103+
>expectLiteral : (p: { props: MyComponentProps; }) => void
104+
>{ props: module.exports } : { props: MyComponentProps; }
105+
>props : MyComponentProps
106+
>module.exports : MyComponentProps
107+
>module : { "export=": MyComponentProps; }
108+
>exports : MyComponentProps
109109

testdata/baselines/reference/submodule/compiler/exportDefaultWithJSDoc1.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
=== b.ts ===
1414
import A from './a'
15-
>A : (string | number)[]
15+
>A : import("./a").NumberLike[]
1616

1717
A[0]
18-
>A[0] : string | number
19-
>A : (string | number)[]
18+
>A[0] : import("./a").NumberLike
19+
>A : import("./a").NumberLike[]
2020
>0 : 0
2121

testdata/baselines/reference/submodule/compiler/exportDefaultWithJSDoc2.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
*/
88

99
export default /** @type {NumberLike[]} */([ ]);
10-
>([ ]) : (string | number)[]
10+
>([ ]) : NumberLike[]
1111
>[ ] : undefined[]
1212

1313
=== b.ts ===
1414
import A from './a'
15-
>A : (string | number)[]
15+
>A : import("./a").NumberLike[]
1616

1717
A[0]
18-
>A[0] : string | number
19-
>A : (string | number)[]
18+
>A[0] : import("./a").NumberLike
19+
>A : import("./a").NumberLike[]
2020
>0 : 0
2121

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
a.js(14,7): error TS2375: Type '{ value: undefined; }' is not assignable to type '{ value?: number; }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
1+
a.js(14,7): error TS2375: Type '{ value: undefined; }' is not assignable to type 'B' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
22
Types of property 'value' are incompatible.
33
Type 'undefined' is not assignable to type 'number'.
44

@@ -19,7 +19,7 @@ a.js(14,7): error TS2375: Type '{ value: undefined; }' is not assignable to type
1919
/** @type {B} */
2020
const b = { value: undefined }; // error
2121
~
22-
!!! error TS2375: Type '{ value: undefined; }' is not assignable to type '{ value?: number; }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
22+
!!! error TS2375: Type '{ value: undefined; }' is not assignable to type 'B' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
2323
!!! error TS2375: Types of property 'value' are incompatible.
2424
!!! error TS2375: Type 'undefined' is not assignable to type 'number'.
2525

testdata/baselines/reference/submodule/compiler/strictOptionalProperties3.types

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const a = { value: undefined }; // error
1919

2020
/** @type {B} */
2121
const b = { value: undefined }; // error
22-
>b : { value?: number; }
22+
>b : B
2323
>{ value: undefined } : { value: undefined; }
2424
>value : undefined
2525
>undefined : undefined

testdata/baselines/reference/submodule/conformance/assertionTypePredicates2.types

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
* @returns { asserts a is B }
1515
*/
1616
const foo = (a) => {
17-
>foo : (a: { x: number; }) => asserts a is { x: number; } & { y: number; }
18-
>(a) => { if (/** @type { B } */ (a).y !== 0) throw TypeError(); return undefined;} : (a: { x: number; }) => asserts a is { x: number; } & { y: number; }
19-
>a : { x: number; }
17+
>foo : (a: A) => asserts a is B
18+
>(a) => { if (/** @type { B } */ (a).y !== 0) throw TypeError(); return undefined;} : (a: A) => asserts a is B
19+
>a : A
2020

2121
if (/** @type { B } */ (a).y !== 0) throw TypeError();
2222
>(a).y !== 0 : boolean
2323
>(a).y : number
24-
>(a) : { x: number; } & { y: number; }
25-
>a : { x: number; }
24+
>(a) : B
25+
>a : A
2626
>y : number
2727
>0 : 0
2828
>TypeError() : TypeError
@@ -39,15 +39,15 @@ export const main = () => {
3939

4040
/** @type { A } */
4141
const a = { x: 1 };
42-
>a : { x: number; }
42+
>a : A
4343
>{ x: 1 } : { x: number; }
4444
>x : number
4545
>1 : 1
4646

4747
foo(a);
4848
>foo(a) : void
49-
>foo : (a: { x: number; }) => asserts a is { x: number; } & { y: number; }
50-
>a : { x: number; }
49+
>foo : (a: A) => asserts a is B
50+
>a : A
5151

5252
};
5353

0 commit comments

Comments
 (0)