* Adds did you mean to the CLI args parser
* Adds test coverage for the did you mean on CLI args
* Adds did you mean to convertOptionsFromJson
* Ensure tsconfig compiler flags also get 'did you mean?'
* Add "use before defined" diagnostic
* Make "use before defined" diagnostic as related information to TS2454
* Add baseline tests for "use before defined"
* Add test for type alias union with undefined for "use before defined" diagnostic
* Update baselines
* Use empty object for invalid package json contents instead of undefined
Fixes#34726
* Behave as if package json doesnt exist in case of invalid json in package json
* Propagate 'undefined' instead of the optional type marker at an optional chain boundary
* Update src/compiler/types.ts
Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
* Fix alias naming and structure bugs in js declarations
* Add another test case and change condition for ns merge to require signature or export content
* Fix typo in comment
* Add isIntersectionConstituent to relation key
isIntersectionConstituent controls whether relation checking performs
excess property and common property checks. It is possible to fail a
relation check with excess property checks turned on, cache the result,
and then skip a relation check with excess property checks that would
have succeeded. #33133 provides an example of such a program.
Fixes#33133 the right way, so I reverted the fix at #33213Fixes#34762 (by reverting #33213)
Fixes#33944 -- I added the test from #34646
* Update comments in test
* resolve require with entity name postfix
For example, `require("x").c`. This is the value equivalent of
`import("x").a.b.c`, but the syntax tree is not as nicely designed for
this purpose.
Fixes#34802
* Add bug number to test
* Add optional chain test
When transforming a module declaration and block, parse tree nodes
contained in the module block have their parent pointers reset due to
`shouldEmitModuleDeclaration` calling into `isInstantiatedModule`, which
needs to set parent pointers to operate.
That causes a crash when later transforming any nodes within the module,
as retrieving their source file in `getSourceFileOfNode` (via
`getOrCreateEmitNode`) fails, due to their new synthesized parent nodes
not being in a source file.
This change avoids the issue by using the parse tree node in `ts.ts` to
decide whether a module declaration should be emitted (i.e. whether the
module contains values).
This means transformers cannot add values to modules that previously did
not contain any.
Fixes#34644.
* Fix incorrectly looking for position in call/new expression arguments when looking for indentation of type arguments
Fixes#32487
* Update src/services/formatting/smartIndenter.ts
Co-Authored-By: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
The constructor function code path in the return type checking of
signatures needs to pass the *merged* symbol of the declaration to
getDeclaredTypeOfClassOrInterface. Other callers of
getDeclaredTypeOfClassOrInterface do this, or used an already-merged
symbol.
Fixes#33993
* Show all matching enum flags in debug formatter
* Revert "Show all matching enum flags in debug formatter"
This reverts commit 073099722a.
* Same thing but simpler
* Lint
The word multi-line and multiline are used interchangeably within the file. Multiline seems to be the most used spelling of the word across the TypeScript repository codebase so a few strings have been updated to keep consistency within a single file. Additionally, corrected a minor capitalization mistake.
* Exclude ?? operator from true/false literal check in createFlowCondition
* Accept new API baselines
* Add tests
* Accept new baselines
* Address CR feedback
* Accept new API baselines
* Avoid a crash with `@typedef` in a script file.
Scripts (as opposed to modules) do not have a symbol object. If a script
contains a `@typdef` defined on a namespace called `exports`, TypeScript
crashes because it attempts to create an exported symbol on the
(non-existent) symbol of the SourceFile.
This change avoids the crash by explicitly checking if the source file
has a symbol object, i.e. whether it is a module.
* Add usage of exports.SomeName typedef.
* Fix bug at bind site rather than in declare func
* Fix expando handling in getTypeReferenceType
getExpandoSymbol looks for the initialiser of a symbol when it is an
expando value (IIFEs, function exprs, class exprs and empty object
literals) and returns the symbol.
Previously, however, it returned the symbol of the initialiser without
merging with the declaration symbol itself. This missed, in particular,
the prototype assignment in the following pattern:
```js
var x = function x() {
this.y = 1
}
x.prototype = {
z() { }
}
/** @type {x} */
var xx;
xx.z // missed!
```
getJSDocValueReference had weird try-again code that relied on calling
getTypeOfSymbol, which *does* correctly merge the symbols. This PR
re-removes that code and instead makes getExpandoSymbol call
mergeJSSymbols itself.
* Remove extra newline
* Restore delayed merge check to getTypeFromJSDocValueReference
This is needed when a function merges with a prototype assignment. The
resulting *merged* symbol is a constructor function marked with
SymbolFlags.Class. However, the merge doesn't happen until
getTypeOfFuncClassEnumModule is called, which, in the
getTypeReferenceType code path, doesn't happen until
getTypeFromJSDocValueReference. That means the check for
SymbolFlags.Class is missed.
Previously, getTypeFromJSDocValueReference had a weird check
`symbol !== getTypeOfSymbol(symbol).symbol`, which, if true, ran
getTypeReferenceType again on `getTypeOfSymbol(symbol).symbol`. For
JS "aliases", this had the effect of dereferencing the alias, and for
function-prototype merges, this had the effect of ... just trying again
after the merge had happened.
This is a confusing way to run things. getTypeReferenceType should
instead detect a function-prototype merge, cause it to happen, and
*then* run the rest of its code instead of relying on try-again logic at
the very end. However, for the RC, I want to fix this code by restoring
the old check, with an additional check to make sure that #33106 doesn't
break again:
```ts
const valueType = getTypeOfSymbol(symbol)
symbol !== valueType.symbol && getMergedSymbol(symbol) === valueType.symbol
```
I'll work on the real fix afterwards and put it into 3.8.
* Add bug number
* Fix crash in expando assignment to alias
This PR disallows expando assignments
Fixes#34493, but disallows the prototype assignment nonetheless.
* Revert mistaken changes
* Fix stack overflow in circular assignment declaration
It also needs to have multiple assignments so that it has a ValueModule
flag.
Fixes#33006
* remove errant comment
* Remove other possible circularity
* Restore fallback with additional condition
Msbuild currently uses a combination of `--listFiles` and `--noEmit` to
obtain a list of files to be consumed by tsc. However, these two flags
don't suppress type checking, the results of which msbuild will never
consume. This new switch gives msbuild a faster way to obtain the file
list.
Note: like `--noEmit`, doesn't make sense in build mode.
Checking for directory existence is expensive and frequently indicates
success. Instead of pre-emptively creating the directory containing a
file to be written, attempt to create the file and only do the directory
scaffolding if the write fails.
Appears to reduce file write time by 10-20% for a file-I/O heavy partner
build.
Thanks to @rbuckton for the suggestion!