Commit 53a756e
authored
Type
* Type `this` in more constructor functions
Previously, `this: this` in constructor functions only when there was
an explicit `@constructor` tag on the function. Now, `this: this` for
any function that's known to be a constructor function.
This improves completions inside constructor functions; also note that
previously the compiler *did* type `this: this` inside methods of constructor
functions, so this fix makes us more consistent. This is reflected in
the large number of baselines that improve.
The fix is a simple switch to `isJSConstructor`, which is the standard
way to detect constructor functions. I'm not sure why the original PR
didn't use this method.
I remember discussing this limitation in the original bug, #25979, and
I guess I decided that it made sense. But I was heavily primed by the bug's
framing of the problem in terms of `noImplicitThis`, which *should*
require an explicit `@constructor` tag.
With better typing comes better detection of `@readonly` assignment; I
had to fix the readonly detection code to use `isJSConstructor` as well.
* Remove `Add @Class tag` fix for noImplicitThis.
The new rules mean that it never applies. It's possible that it should
apply to functions like
```js
function f() {
this.init()
}
```
In which `init` is never defined, but I think this program is incomplete
enough that not offering the fix is fine.
* Fix precedence of `@this`
Previously, both `@class` and `@this` in a jsdoc would cause the `@this`
annotation to be ignored. This became a worse problem with this PR,
because `this` is correctly typed even without the annotation.
This commit makes sure that `@this` is checked first and used if
present.this in more constructor functions (#39447)1 parent 030f5e8 commit 53a756e
File tree
104 files changed
+376
-215
lines changed- src
- compiler
- services/codefixes
- tests
- baselines/reference
- cases
- conformance/jsdoc
- fourslash
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
104 files changed
+376
-215
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22440 | 22440 | | |
22441 | 22441 | | |
22442 | 22442 | | |
| 22443 | + | |
22443 | 22444 | | |
22444 | 22445 | | |
22445 | | - | |
22446 | | - | |
22447 | | - | |
22448 | | - | |
22449 | | - | |
22450 | | - | |
22451 | | - | |
| 22446 | + | |
| 22447 | + | |
| 22448 | + | |
| 22449 | + | |
| 22450 | + | |
| 22451 | + | |
22452 | 22452 | | |
22453 | 22453 | | |
22454 | | - | |
22455 | | - | |
22456 | | - | |
22457 | | - | |
22458 | | - | |
22459 | | - | |
22460 | | - | |
22461 | | - | |
22462 | | - | |
22463 | | - | |
| 22454 | + | |
| 22455 | + | |
| 22456 | + | |
| 22457 | + | |
22464 | 22458 | | |
22465 | 22459 | | |
22466 | | - | |
22467 | 22460 | | |
22468 | 22461 | | |
22469 | 22462 | | |
| |||
22475 | 22468 | | |
22476 | 22469 | | |
22477 | 22470 | | |
22478 | | - | |
22479 | | - | |
22480 | | - | |
22481 | | - | |
22482 | | - | |
22483 | | - | |
22484 | 22471 | | |
22485 | 22472 | | |
22486 | 22473 | | |
| |||
28574 | 28561 | | |
28575 | 28562 | | |
28576 | 28563 | | |
28577 | | - | |
| 28564 | + | |
28578 | 28565 | | |
28579 | 28566 | | |
28580 | 28567 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | 55 | | |
61 | 56 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | | - | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| 54 | + | |
| 55 | + | |
52 | 56 | | |
53 | 57 | | |
54 | 58 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
| 55 | + | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
| 196 | + | |
| 197 | + | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| |||
0 commit comments