* Merge multiple symbols even when re-exported
As far as I remember, the target of `mergeSymbol` needs to be a merged
symbol, not a symbol with a mergeId that points to mergedSymbol.
However, mergeSymbolTable didn't check for this.
I can't remember if symbol tables may contain
symbols-with-mergeId. If they can, then mergeSymbolTable needs to call
getMergedSymbol on the individual targets of the merge. That's what I
did in this PR.
* Call getMergeSymbol eagerly
On the source, not target, of mergeSymbolTable's contents
* Fixed a false positive related to binding patterns and spread expressions
* Improve ancestor lookup when checking if an expression is spread into an object
* Fixed ancestor lookup for more node types
* Remove equality check for contextual types
* Reformat code
* Use `isWithinSpreadAssignment` flag + `objectsWithinSpread` cache instead of ancestor traversal
* Revert "Use `isWithinSpreadAssignment` flag + `objectsWithinSpread` cache instead of ancestor traversal"
This reverts commit be387e3bbf8a5cce2bc4c31fd77b061ea6cf8e0b.
* Expand on the existing comment
* Update error messages for CJS imports resolving to ES modules
* Update error message
* Use package scope from source file
* Update baselines
* Issue error for JSX/TSX files
* Switch from related info to message chain
* Write a test and a huge comment
* Finish fixing everything
* Clean up comment
* Remove obsolete comment
* Fix comment trailing off
* Optimize to hit the file system much less
* Improve import type support for commonjs exports
This PR makes getTypeFromImportTypeNode a little more like
getExternalModuleMember: for JS files, it now uses both
`getTypeOfSymbol` and `getExportsOfSymbol`, and uses whichever one
returns a symbol. This allows using arbitrary properties of a CJS export=
as types in JSDoc; previously a special case in the binder enabled only
CJS export= where all properties were shorthand assignments.
Fixes#49195
* Add js types/value test case
* Improve binding of CJS property assignments
1. Bind property assignments same as shorthand property assignments in
module.exports object literal assignments.
2. Bind all such assignments, even if the object literal contains
non-property assignments. This is different from before, and it requires
slightly smarter code to prefer aliases when checking CJS imports.
* Remove new binder code
Just include the original fix
* revert missed type in binder
* Add test where the errors are reported in different file
Test for #49739
* Report error only on local declaration with additional related information
Fixes#49739
* Handle existing tests
* Account for type parameters in missing function codefix
* Apply suggestions from code review
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
* WIP
* Synthesize new type parameters instead of deep unions and intersections
* Pass along type parameter constraints
* E.T. phone home
* Clean up comments just a bit
* Only widen the instance type sometimes
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
* fix(49719): omit TS2301 error with enabled usedefineforclassfields
* show error for target lower than esnext with useddefineforclassfields enabled
* change target from esnext to es2022
* Copy type parameters to function with @type tag
Previously, type references to generic types would fail to copy type
parameters from type references in an `@type` tag. Now the type
parameter is copied.
Note that I left 3 places in the checker unchanged, even though they
should technically also get type parameters from type refereneces:
1. getOuterTypeParameters -- not fixing this means that nested function
still won't get instantiated correctly. I'll see how hard this is to
fix.
2. getLocalTypeParameterOfClassOrInterfaceOrTypeAlias -- only applies to
constructor functions which have a type annotation, which doesn't type
check in the first place.
3. isThislessType -- This function is conservative, so should be
possible to make it more conservative without writing a lot of code.
Fixes#49039
* Update API baselines
* Improve narrowing logic for instanceof, type predicates, and assertions
* Accept new baselines
* Add tests
* Tweak algorithm
* Accept new baselines
* Optimize for discriminated unions