* Accept change
* Accept the huge set of ever so slightly changed baselines
* Update return type logic to only reuse nodes if original nodes share scope with current node, like property types, only reuse nodes if symbols referened are acessible, reuse nodes for property signatures, too
* Only reuse nodes when a context is provided (otherwise identifier printback may fail)
* Only track symbol if symbol is found and no error is recorded
* Fix type parameter reuse lookup
* Forbid cjs module.exports references in retained nodes
* Adjust check for cjs export references to not include bad module type in output
* Add symbol to all identifiers we see in existing nodes for quickinfo
* Accept fourslash baseline updates
* Accept slightly updated baseline post-merge
* Do not copy original nodes for error types, replace empty type references with any
* Add the 'awaited' type operator
* Add script to manually add reviewers to a PR when GH 'Suggested Reviewers' breaks
* Fix lint error in review script
* Only defer generic awaited type for possible thenable
* Add variance-like behavior for awaited
* Switch awaited type params to 'unreliable' variance
* fix typo in inferTypes
* LKG without syntax in lib
* LKG with new syntax in lib
* Add 'strictAwaitedTypes' flag
* Treat strictAwaitedTypes as strict-mode flag
* Rename TAll, remove duplicate definition of 'race'
* Apply suggestions from code review
Co-Authored-By: ExE Boss <3889017+ExE-Boss@users.noreply.github.com>
* Fix inference priority
* Update comment to isGenericAwaitableType
* Add overloads for then/catch to Promise
* Add inference heuristic for T | PromiseLike<T> (for any PromiseLike)
* Remove strictAwaitedTypes flag
Co-authored-by: ExE Boss <3889017+ExE-Boss@users.noreply.github.com>
* Added @ts-expect-error to @ts-ignore directives
Similar to `// @ts-ignore`, but will itself cause a new error diagnostic if it does not cause an existing diagnostic to be ignored.
Technical summary:
1. The scanner will now keep track of `CommentDirective`s it comes across: both `@ts-expect-error` and `@ts-ignore`
2. During type checking, the program will turn those directives into a map keying them by line number
3. For each diagnostic, if it's preceded by a directive, that directive is marked as "used"
4. All `@ts-expect-error` directives not marked as used generate a new diagnostic error
* Renamed to getDiagnosticsWithPrecedingDirectives per suggestion
* Added JSDoc comment I thought I did already
Co-authored-by: Orta <orta.therox+github@gmail.com>
* More precise property-overwritten-by-spread errors
Trying to do this check in getSpreadType just doesn't have enough
information, so I moved it to checkObjectLiteral, which is a better
place for issuing errors anyway.
Unfortunately, the approach is kind of expensive in that it
1. creates a new map for each property and
2. iterates over all properties of the spread type, even if it's a
union.
I have some ideas to improve (1) that might work out. I'm not sure how
bad (2) is since we're going to iterate over all properties of all
constituents of a union.
Fixes#36779
* another test and rename
* Remove bogus @implements errors
Make the search for the actual host more comprehensive by reusing the
code that previously only searched for functions. I don't know what to
call this function now, since the old name wasn't accurate either.
* undo gratuitous name change
* Improve name and make calling more uniform
It's slightly less efficient but I think worthwhile for readability.
* Treat never-like intersections as never
* Accept new baselines
* Fix compiler issues revealed by increased intersection correctness
* Delete fourslash tests that are no longer applicable
* Include isNeverLikeIntersection check in getNormalizedType
* Erase never-like types in several more places
* Check that base types are not never-like
* Add comments
* Revert isNeverLikeType check in getIndexType (keyof shouldn't resolve member types)
* Introduce getReducedType for union and intersection types
* Don't reduce in getApparentType
* Avoid relationship check in resolveMappedTypeMembers
* Accept new baselines
* Don't call getReducedType in getIndexType
* Ensure reduced and unreduced forms of a type can compare identical
* Reduce types before converting them to string representation
* Accept new baselines
* Reduce intersections before obtaining keyof X
* Add tests
* Accept new baselines
* Fix comment in tests
* Don't infer from empty intersection types
* Add tests
* Accept new baselines
* Defer instantiation of mapped type property types
* Accept new baselines
* Include more precise type in diagnostic
* Accept new baselines
* Minor optimization
* Improve error message
* Optional properties in intersections are never discriminants
* Adding support for @implements.
* Fixed code review issues for @implements, added some more tests.
* Fixed declaration emit for @interface
* Improved getImplementsTypes to not cache the results since it is only used once.
* Removed unnecessary checks from getImplementsTypes
THe code to bind `@enum` and `@typedef` didn't handle the case that the
`@enum` was on a property assignment to an alias of module.exports.
Specifically, `x` needs to be correctly aliased to the file's symbol in
the example below:
```
var x = module.exports = {};
/** @enum {string} */
x.E = {
A: "A"
};
```
* Add test
* Fix superfluous error when destructuring from object that includes spread assignment
* Update baseline to include error case
* Remove redundant check
* add tests but not baselines or fixes
* Update original change
Still probably wrong; probably doesn't even compile beacuse I'm just
typing on my laptop.
* fix error code ok
* notes to self
* Error: property is specified more than once via spread
* make jsx tests stricter
* update semicolon error message
* use ?. because it is great
* use maybeTypeOfKind in new code
* restore jsx error
* add tests
* Handle when files get checked in different orders
* Fix interface extends clause
* Fix import= something type only from a module
* Revert apparently unnecessary addition
* Revert "Revert apparently unnecessary addition"
This reverts commit 7444b0b72e.
* Disallow `import = a.b.c` on anything with type-only imports
* Safety first
* Add test for TS Server single-file open
* Add big comment
* Extract error reporting function for import aliases
* Delete blank line
* Un-export, comment, and colocate some utils
* Combine 3 type-only marking function calls into one
* Add more export default tests
* Class fields w/esnext+[[Define]]:no shadow error
With useDefineForClassFields: true and ESNext target, initializer
expressions for property declarations are evaluated in the scope of
the class body and are permitted to reference parameters or local
variables of the constructor. This is different from classic
Typescript behaviour, with useDefineForClassFields: false. There,
initialisers of property declarations are evaluated in the scope of
the constructor body.
Note that when class fields are accepted in the ECMAScript
standard, the target will become that year's ES20xx
* add negative test case
* Add explanatory comment
Previously the jsdoc index signature syntax was incorrectly treated the
same as Object:
```js
/** @typedef {Object} AllowsNesting
* @property ... */
/** @typedef {Object.<string,string>} IncorrectlyAllowsNesting */
```
Fixes#34911
* Add constructor functions to aliasable expressions
Fixes#35228, at least the crash. There are still a couple of errors
that are probably incorrect.
Note that isJSConstructor relies on parent pointers and the ability to
merge symbols, so I had to move isAliasSymbolDeclaration (back?) to the
checker.
* add simple test case
* remove errors in test
* fix bad merge
* Fix getExpandoSymbol for already-expando symbols
getExpandoSymbol is intended to get the symbol of the expando in a
declaration like
```js
var C = class {
}
```
However, when this occurs in a `module.exports` assignment, alias
resolution already jumps to the exported symbol -- in this case the
expando symbol:
``js
// @filename: first.js
module.exports = class {
}
// @filename: other.js
/* @type {import("./first")} */
var C
```
`getExpandoSymbol` is then called on `class { }` instead of
`module.exports = class { }`.
Previously, `getExpandoSymbol` would incorrectly treat `class { }` the
same as the export assignment and get the expando ... from the expando
itself. This resulted in merging the expando with itself, which causes
bogus errors and could cause other problems.
Now `getExpandoSymbol` checks that the expando "initializer" is
different from the declaration.
* Better check for getExpandoSymbol of expando
Check the declaration directly instead of the initialiser.
* ESNext+[[Define]]: reference to param props illegal
When target: "esnext" and useDefineForClassFields: true, property
declaration initialisers should not be able to reference parameter
properties; class fields are initialised before the constructor runs,
but parameter properties are not:
```ts
class C {
foo = this.bar
constructor(public bar: string) { }
}
```
emits code that looks like this:
```js
class C {
bar
foo = this.bar
constructor(bar) {
this.bar = bar
}
}
new C('x').foo.length // crashes; foo is undefined
```
This PR adds an error on foo's declaration with ESNext+[[Define]].
* improve test
* Emit statements before super
When statements come before super, Typescript's emit is incorrect,
whether there is an error or not. This change preserves statements that
come before super whether there is an error or not.
Here is the case with no errors:
```ts
class Test extends Array {
p: number
constructor() {
console.log("p is initialised in the constructor below super()")
super()
this.p = 1
}
}
```
Notice that `p` is manually initialised in the constructor after
`super()` instead of at the property declaration.
* Update baselines
Parameter properties in the error case now move below the super call.
This is an improvement because it means the code is more likely to execute
correctly.
* remove outdated comments
* Change type-only semantics to allow type queries
* Don’t error using type-only import in ambient context
* Fix default import
* Fix namespace import
* Update more baselines
* Prevent circular resolution
* Track const enum expression usage
* Update baselines
* Perf tuning 1
* Test commit for perf impact
* Weave type-only alias declaration finding into alias resolution
* Fix namespace import of type-only exported symbols
* type-only exports do not contribute to the module object type
* Update APIs
* Fix enum casing, remove type-only conversion suggestion
* Short circuit type-only checks in resolveEntityName faster
* Fix casing in API
* Remove unused parameter
* Fix error on qualified names in type queries
* Allow type-only imports in computed property names
* Fix computed property names of types and abstract members
* Remove unused util
* Commit missing baselines
* Rename “check” functions so as not to overload the word “check”
Previously these were incorrectly treated just like normal properties:
```ts
class Parent {
a: any;
constructor(arg: any) {
this.a = arg;
}
}
class Child extends Parent {
declare a: number;
constructor(arg: number) {
super(arg);
console.log(this.a); // Property 'a' is used before being assigned. (2565)
}
}
```
Fixes#35327
* Check combined intersection properties against target index signatures
* Add tests
* Accept new baselines
* Less aggressive check for index signatures
* Track intersection membership state for both source and target
* Minor fixes