* constructor functions infer from call+construct
Also fix an incorrect combining of inferences for rest parameters: the
inferred types will be arrays in the body of the function and the
arguments from outside the function will be the element type.
* All functions infer from call+construct contexts
* infer from usage's unification uses multiple passes
Previously, the unification step of infer-from-usage codefix would stop
as soon an answer was found. Now it continues if the result is
*incomplete*, with the idea that later passes may provide a better
inference.
Currently, an *incomplete* inference is
1. The type any.
2. The empty object type `{}` or a union or intersection that contains
`{}`.
In the checker, any takes priority over other types since it basically
shuts down type checking. For type inference, however, any is one of the least
useful inferences.
`{}` is not a good inference for a similar reason; as a parameter
inference, it doesn't tell the caller much about what is expected, and
it doesn't allow the function author to use an object as expected. But
currently it's inferred whenever there's an initialisation with the
value `{}`. With this change, subsequent property assignments to the
same parameter will replace the `{}` with a specific anonymous type. For
example:
```js
function C(config) {
if (config === undefined) config = {};
this.x = config.x;
this.y = config.y;
this.z = config.z;
}
```
* Unify all passes of inference from usage
In the previous commit, I changed inference from usage to continue
inference if a the result was *incomplete*. This commit now runs all 4
inference passes and combines them in a unification step. Currently the
unification step is simple, it:
1. Gathers all inferences in a list.
2. Makes properties of anonymous types optional if there is an empty
object in the inference list.
3. Removes *vacuous* inferences.
4. Combines the type in a union.
An inference is *vacuous* if it:
1. Is any or void, when a non-any, non-void type is also inferred.
2. Is the empty object type, when an object type that is not empty is
also inferred.
3. Is an anonymous type, when a non-nullable, non-any, non-void,
non-anonymous type is also inferred.
I think I might eventually want a concept of priorities, like the
compiler's type parameter inference, but I don't have enough examples to
be sure yet.
Eventually, unification should have an additional step that examines the
whole inference list to see if its contents are collectively
meaningless. A good example is `null | undefined`, which is not useful.
* Remove isNumberOrString
* Unify anonymous types
@andy-ms pointed out that my empty object code was a special case of
merging all anonymous types from an inference and making properties
optional that are not in all the anonymous type. So I did that instead.
* Use getTypeOfSymbolAtLocation instead of Symbol.type!
* Unify parameter call-site inferences too
Because they still have a separate code path, they didn't use the new
unification code.
Also some cleanup from PR comments.
* Add object type unification test
Also remove dead code.
* Only use fallback if no inferences were found
Instead of relying on the unification code to remove the fallback.
* Measure variance of aliased conditional types using variance markers
* Just do variance probing for all type aliases
* Small limiter for predictability
* Inline property set, remove unused functions
* Correct indentation, using correct (I hope) indentation code
Note that part of the code, in formatting.ts, is cloned but should be
extracted to a function instead.
* Remove some possibly-superfluous code
But I see 4 failures with whitespace, so perhaps not.
* Restrict indentation change to avoid breaking baselines
The indentation code is very complex so I'm just going to avoid breaking
our single-line tests for now, plus add a simple jsdoc test to show that
multiline jsdoc indentation isn't destroyed in the common case.
* Switched over to construction for @return/@type
Still doesn't merge correctly though
* Add @return tags to emitter
* Merge multiple jsdocs
(not for @param yet)
* Merge multiple jsdoc for parameters too
* Emit more jsdoc tags
Not all of them; I got cold feet since I'll have to write tests for
them. I'll do that tomorrow.
* Many fixes to JSDoc emit
And single tests (at least) for all tags
* Cleanup in textChanges.ts
* Cleanup in formatting.ts
(Plus a little more in textChanges.ts)
* Cleanup in inferFromUsage.ts
* Fix minor omissions
* Separate merged top-level JSDoc comments with \n
instead of space.
* Don't delete intrusive non-jsdoc comments
* Cleanup from PR comments
1. Refactor emit code into smaller functions.
2. Preceding-whitespace utility is slightly easier to use.
3. Better casts and types in inferFromUsage make it easier to read.
* Fix bogus newline
* Use @andy-ms' cleanup annotateJSDocParameters
* Support 'isSourceFileFromExternalLibrary' for source files from '/// <reference types="" />''
* Calculate `isExternalLibraryImport` at the end
* Calculate isExternalLibraryImport with symlink path
* Add new special assignment kinds for recognizing Object.defineProperty calls
* Add support for prototype assignments, fix nits
* Fix code review comments
* Add test documenting behavior in a few more odd scenarios
* Unify JSX Call Checking Codepaths
* Add tests for fixed issues
* Fix lint, move all error checking into the only-run-once resolveSignature call
* Remove unused (unreachable?) code path
* Consolidate a little more duplicated logic into signature checking
* Fix#19775 a bit more
* Cosmetic changes from CR
JSDoc types references can often be to values, which can often be
circular in ways that types tied to declarations cannot. I decided to
create a separate property on SymbolLinks rather than reusing
declaredType, although I'm not sure that's strictly required.