* Revert "Stop looking at binding patterns for type argument inference (#45719)"
This reverts commit be618b1446.
* Update error baseline for moved lib file declaration
* fix: add override errors for js class members
* fix: test failures of js override error message
* update diagnostic messages
* fix: test errors
* fix: lint errors
* Adds 'Awaited' type alias and updates to Promise.all/race/allSettled/any
* Use Awaited<T> with 'await'
* Clean up overloads
* Further restrict 'Awaited<T>' auto-wrapping for 'await'
* Minor fixes to convertToAsync
* Back out on nested return in inner continuation
* Baseline update
* Verify type argument for call can be used, add a few more early exit shortcuts
* fix for 45006
* treat setters like getters in preceding commit; move test accordingly
* fix test baselines
* changes per code review
in `getContainerFlags`, move cases for get/set accessors
to fallthrough into the block that currently handles MethodDeclaration;
so get/set accessors and method declarations all get the same container flags,
such that during `bindContainer`, `startFlow.node` is assigned to
getters/accessors
(this changes a public api in tsserverlibrary.d.ts and typescript.d.ts
by adding `GetAccessorDeclaration` and `SetAccessorDeclaration` to the type
of `FlowStart.node`)
consolidate predicates checking whether a node is either a get or set
accessor, into `isObjectLiteralOrClassExpressionMethodOrAccessor`
(formerly `isObjectLiteralOrClassExpressionMethod`)
annotate updated test with `@target: es2020`
* fix `isObjectLiteralOrClassExpressionMethodOrAccessor`
require that Getter/Setters are parented by an ObjectLiteralExpression or ClassExpression
* Simple first version
Doesn't cover or test any complicated variations.
* Lots of cases work
Destructuring does not. But
- skipping node_modules and lib.* does.
- call expressions does
- property access, including with private identifiers, does
* Support variable declarations, property assignments, destructuring
As long as it's not nested
* More cleanup
* skip all d.ts, not just node_modules/lib
* Offer a codefix for a lot more cases
* remove incorrect tuple check
* Use getSymbolId instead of converting to string
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
* add test + switch to tracking number symbol ids
* Address PR comments
* Exclude tuples from suggestion
* Better way to get error node
Plus add a check that errorNode is an argument to the call, not the
call's expression.
* fix semicolon lint
* fix another crash
* Simplify: add undefined to all optional propertie
whether or not somebody tried to assign undefined to them in the
erroneous assignment
* remove fix-all
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
* Fix check in hasNonBindingPatternContextualTypeWithNoGenericTypes
* Add regression tests
* Accept new baselines
* Compute both ObjectFlags.IsGenericXXXType flags in one go
* Fix getting completion details for meta properties.
* Move inside the worker.
* Move ImportMeta handling to completions.ts
* Fix property type name for new.target.
* Use symbols for ImportMeta completions.
* Accept baselines.
* Revert lib change.
* Revert needless parser change.
* Missed these reverts.
* Remove now unused `isMetaPropertyExpression`
* Move up meta property keyword check to be done in `getSymbolAtLocation` and `getTypeOfNode`
* Call `checkNewTargetMetaProperty` directly and handle when it's an error type.
* Make meta property expression types synthetic.
* Make event.target and import.meta properties readonly
* Add a test for go to definition (I think?)
* Copy built-in types/values test for go to definition.
* Add tests for go to definition when not a module.
* Fix "go to definition" for new.target
* don't track computed name if symbol has no declaration
* add compiler test
* add non serializable property declaration emit error
* don't track computed name if symbol has no declaration
* fix small stuff
* rebase: add non serializable property declaration emit error
* use symbolToString instead of symbolName
* ensure export modifier is used before default modifier
* gracefully handle `default function`
* Revert "gracefully handle `default function`"
This reverts commit 1d8e288754.
* give better error message on default without leading export
* Check entire access path is constant when narrowing by inlining
* Add tests
* Accept new baselines
* Added test cases for parameter properties.
* Accepted baselines.
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
* Issue unawaited promise error on symbol-less expressions
* Use same behavior for call expressions
* Revert "Use same behavior for call expressions"
This reverts commit 60d58132e4.
* CFA inlining of conditional expressions referenced by const variables
* Accept new baselines
* Add tests
* Accept new baselines
* Increase inlining limit to 5 levels per design meeting discussion
* Class static block (#9)
* Add types factory and parser
* Add some case
* Make class static block as a container
* Update cases
* Add visitor
* Add emitter and more compile target
* Check boundary of break and continue
* Add basic transformer
* Fix emit behavior
* Add more tests
* Add friend tests
* Update baseline
* Fix cr issues
* Accept baseline
* Add decorator and modifier check
* Add functional boundary check
* Fix conflict
* Fix computed prop name within context
* Add more tests
* Update baseline
* Avoid invalid test baseline
* Support use before initialize check
* wip
* Fix class static block context
* Fix checks
* Fix missing case
* Improve assert message
* Accept baseline
* Avoid new context
* Update diagnostic message
* Fix name collision
* Fix targets
* Avoid unnecessary files
* Add more case
* Add more test cases
* Fix strict mode function declaration
* Avoid private fields initializer if no private identifier references
* Avoid private fields and add more test case
* Add more case
* Add tests and support for related services functionality
* Fix this reference in static block
* Split parser diagnostic and binder diagnostic
Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
* Add signature arguments label support
* Support rest parameters and destruction
* make lint
* Fix tuple rest parameters
* Adjust name styles
* Rename to inline hints
* Partition inline hints
* Adjust range pred
* Add function expression like hints
* Support configure inline hints
* Display hints in single line
* Add test suits and tests
* Add range tests
* Support more hints
* Add more options
* Fix logical
* Add more cases
* Support call chains
* Rename options
* Match lastest protocol
* Update protocol changes
* Support context value and hover message
* Revert "Support context value and hover message"
This reverts commit 37a7089633.
* Revert "Update protocol changes"
This reverts commit e5ca31bc30.
* Add hover message
* Accept baseline
* Update src/services/inlineHints.ts
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
* Update src/services/inlineHints.ts
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
* Cache across the program
* Fix possible undefined
* Update protocol changes
* Fix missing property
* Make lint happy
* Avoid call chain hints
* I'm bad
* Add whitespace before type
* Add more tests
* Should care about jsdoc
* Support complex rest parameter
* Avoid module symbol hints
* Care about leading comments
* Fix CR issues
* Avoid changes
* Simplify comments contains
* Fix CR issues
* Accept baseline
* Check parameter name before create regex
* Rename option
* Avoid makers
* Skip parens for argument
* Fix CR issues
* Fix enums
* Accept baseline
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
* Fix 'arguments' check in class field initializer or static initialization block
* return errorType
* Merge branch 'master' of https://github.com/exoticknight/TypeScript
* use isInPropertyInitializer
fix Diagnostics message
* Switch index signature storage to 'indexInfos: IndexInfo[]' property
* Accept new baselines
* Remove another usage of IndexKind enum
* Update getIndexedAccessType and resolveMappedTypeMembers
* Accept new baselines
* Update grammar checking for index signatures
* Accept new baselines
* Consider all index signatures in mapped types and union types
* Accept new baselines
* Update getIndexType
* Accept new baselines
* Intersect multiple applicable index signatures
* Use getApplicableIndexInfo instead of hardwired string/number handling
* Update index signature relationship checking
* Report type for which index signature is missing
* Report type for which index signature is missing
* Accept new baselines
* Make 'number' index signatures consistently apply to numeric strings
* Accept new baselines
* Update fourslash test
* Revise index constraint checking
* Accept new baselines
* Update error messages
* Accept new baselines
* Update type inference from index signatures
* Update isKnownProperty
* Update contextual typing based on index signatures
* Accept new baselines
* Support union types in index signature declarations
* Accept new baselines
* Check duplicate index signatures / remove redundant template literals from unions with string
* Accept new baselines
* Include key type in diagnostic / check symbol-named properties
* Accept new baselines
* Minor fix
* Add tests
* Accept new baselines
* Add optimized findApplicableIndexInfoForName
* Accept new baselines
* Another place we don't need to obtain literal type for property name
* Accept new baselines
* Don't create literal types that are going to be discarded
* Individual maps for string, number, bigint, and enum literal types
* Remove ineffective optimizations
* Accept new baselines
* Permit intersections as key types in index signatures
* Index expression in element access is template literal context
* Add tests
* Accept new baselines
* Symbol index signatures from object literals with computed symbol properties
* Accept new baselines
* Add more tests
* Accept new baselines
* Implement Go To Definition for all applicable index signatures
* Add fourslash test
* Accept new API baselines
* Don't attach declarations to symbols in mapped types with 'as XXX' clauses
* Add test (and tweak comment)
Co-authored-by: Eli Barzilay <eli@barzilay.org>
* Always issue cannot find name did-you-mean error
This PR issues "cannot find ${name}, did you mean ${name}" errors for
identifiers and propery access expressions in JS files *without*
`// @ts-check` and without `// @ts-nocheck`. This brings some benefits of
Typescript's binder to all Javascript users, even those who haven't
opted into Typescript checking.
```js
export var inModule = 1
inmodule.toFixed() // errors on exports
function f() {
var locals = 2
locale.toFixed() // errors on locals
}
var object = {
spaaace: 3
}
object.spaaaace // error on read
object.spaace = 2 // error on write
object.fresh = 12 // OK, no spelling correction to offer
```
To disable the errors, add `// @ts-nocheck` to the file. To get the
normal checkJs experience, add `// @ts-check`.
== Why This Works ==
In a word: precision. This change has low recall — it misses lots
of correct errors that would be nice to show — but it has high
precision: almost all the errors it shows are correct. And they come
with a suggested correction.
Here are the ingredients:
1. For unchecked JS files, the compiler suppresses all errors except
two did-you-mean name resolution errors.
2. Did-you-mean spelling correction is already tuned for high
precision/low recall, and doesn't show many bogus errors even in JS.
3. For identifiers, the error is suppressed for suggestions from global files.
These are often DOM feature detection, for example.
4. For property accesses, the error is suppressed for suggestions from
other files, for the same reason.
5. For property accesses, the error is suppressed for `this` property
accesses because the compiler doesn't understand JS constructor
functions well enough.
In particular, it doesn't understand any inheritance patterns.
== Work Remaining ==
1. Code cleanup.
2. Fix a couple of failures in existing tests.
3. Suppress errors on property access suggestions from large objects.
4. Combine (3) and (4) above to suppress errors on suggestions from other, global files.
5. A little more testing on random files to make sure that precision
is good there too.
6. Have people from the regular Code editor meeting test the code and
suggest ideas.
* all (most?) tests pass
* NOW they all pass
* add tonnes of semi-colons
* restore this.x check+add a test case
* make ts-ignore/no-check codefix work in unchecked js
* Issues errors only in the language service
* add a few more tests
* fix incorrect parentheses
* More cleanup in program.ts
* Improve readability of isExcludedJSError
* make diff in program.ts smaller via closure
* Switch unchecked JS did-you-mean to suggestion
Instead of selectively letting errors through.
* undo more missed changes
* disallow ignoring suggestions
* Issue different messages for plain JS than others
Straw text for the messages, I just changed the modals to avoid name
collisions.
* Fix discovery of more pnpm symlinks
* Add some tests
* Never show pnpm paths in auto imports, even if there’s no other path
* Import statement completions can return none
* Fix tests
* Add failing test showing poor symlink cache reuse
* Fix test, fails for right reasons now
* Preserve cache built up during program creation, then fill in with program resolutions
* Remove obsolete comment
* Remove obsolete type assertion
* Revert fully filtering out ignored paths
* Add test case for 'useUnknownInCatchVariables'.
* Add new 'useUnknownInCatchVariables' flag.
* Accepted baselines.
* Add test for catch variable explicitly typed as 'any'.
* Accepted baselines.
* Move option under 'strict'.
* Accepted baselines.
* 'useUnknownInCatchVariables' is strict in command line help.
* Add unqualified JSDoc member references
This allows unqualified references like:
```ts
class Zero {
/** @param buddy Must be {@link D_HORSE} or {@link D_DOG}. */
deploy(buddy: number) { }
static D_HORSE = 1
static D_DOG = 2
}
```
I surveyed @see and @link again to estimate how common this is. I found
a little over 200 uses, which is around 2%. Sorted by frequency, this
*is* the next feature on the list, along with the `module:` prefix.
So I think this is about the right point to stop adding code.
In this case, however, I liked most of the uses -- there were a lot
of deprecated functions that referenced a function just below, where it
would be wordy to qualify the name, but the reader would benefit from a
link.
Note that unqualified references do *not* work inside type or object
literals. The code I ended up with is quite complicated and I didn't
observe any uses in the wild.
Fixes#43595
* Remove type/object literal container check
Since they don't work anyway
* Ensure static index signatures have an errorNode available
* Lookup static index signature declarations in the right symbol table, stop checking prototype props
* Add @linkcode and @linkplain tags
They are just like @link tags but request fixed-width and normal
presentation, respectively.
Fixes#43935
* revert JSDocComment -> JSDoc SyntaxKind rename
* update API baselines
* fix lint
* support QualifiedName when narrowing inside loops
* add test
* narrow more qualified names
* handle `undefined` of `getFlowCacheKey `
* update comments in test
* Everything mostly works
A couple of mixed, nested references don't work yet.
The scanner+parser interaction is wrong, the parser consumes one too
many spaces, and the checker+services code needs a little cleanup.
* Cleanup
1. I decided that correctly parsing a#b.c, an entity name containing an
instance reference, is not worth the work.
2. I made the scanner, at least the jsdoc part, emit a # token, and
provided a reScanPrivateIdentifier in order to convert #a to # a.
3. I cleaned up the code in the checker.
2. Unrelated: I added a missing space in linkPart display.
* Cleanup lint + var naming
* investigate+clean up a couple of TODOs
* Fix lint in utilities.ts
* change name to JSDocMemberName
* address PR comments