Commit Graph

8153 Commits

Author SHA1 Message Date
Wesley Wigham
fefc47fae3 Flag JS Literals and ignore assignments/accesses to invalid props, instead of adding an index (#25996)
* Remove index signatures from js literals, use an object flag to indicate errors should be ignored instead

* Add focused test on the keyof problem

* Fix fourslash test

* Reenable errors with noImplicitAny flag

* Also disable excess property checks outside of noImplicitAny mode for js literals

* Edit and move comments
2018-08-02 13:40:44 -07:00
Ryan Cavanaugh
3ab7a98ecf Merge pull request #26121 from mattmccutchen/issue-23999
"Could not find a declaration file for module" error needs to use the unmangled package name where appropriate.
2018-08-01 20:55:31 -07:00
James Keane
50f442f9ff Fixes #26122 - erroneous "TS2350" for js constructors called with incorrect parameters (#26124)
* Fixes #26122.

When `resolveCall` does not resolve in `resolveNewExpression`, the error should only be thrown if there is a *defined* signature that is not-void.

* Fix other baselines to remove erroneous TS2350.
2018-08-01 13:40:55 -07:00
Matt McCutchen
d054621477 "Could not find a declaration file for module" error needs to use the
unmangled package name where appropriate.

Add a test case for an untyped sub-module of a scoped package with
typings.  The other diagnostic message is covered by existing tests; I
guess no one looked at the baselines closely enough.

Fixes #23999.
2018-08-01 14:13:38 -04:00
Andy
9c9f3e3cf9 importFixes: When one file redirects to another, consider both for global import specifiers (#25834)
* importFixes: When one file redirects to another, consider both for global import specifiers

* Add test for #26044

* Avoid a symlinked package globally importing itself (fixes another case of #26044)

* Compare to node_modules with getCanonicalFileName
2018-07-31 17:28:56 -07:00
Andy
f326b4b7cb Make import fix for default import mention that it's a default import (#26105) 2018-07-31 17:28:35 -07:00
Andy
1599ee2805 Always return a defined result from getTypeFromTypeNode (#26108) 2018-07-31 17:28:15 -07:00
Wesley Wigham
2edc47bc67 Fix decorated accessor emit (#26016) 2018-07-31 13:53:28 -07:00
James Keane
dfedb24f75 Jsdoc @constructor - in constructor properly infer this as class instance (#25980)
* Properly infer `this` in tagged `@constructor`s.

`c.prototype.method = function() { this }` was already supported.

This commit add support to two more kinds relying on the JSDoc
`@constructor` tag. These are:
 1. `/** @constructor */ function Example() { this }`
 2. `/** @constructor */ var Example = function() { this }`

* Update the baseline for js constructorFunctions.

C3 and C4 `this` was set as `any`, now it is properly showing as
the class type.

* Fix lint errors

* Add circular initialisers to constructo fn tests.

* Error (`TS2348`) if calling tagged js constructors

When calling a JS function explicitly tagged with either `@class` or
`@constructor` the checker should throw a TS2348 not callable error.

* Don't resolve jsdoc classes with construct sigs.

This undoes the last commit that sought to change how js functions
tagged with `@class` were inferred. For some reason, currently
unknown, giving those functions construct signatures causes issues
in property assignment/member resolution (as seen in the
`typeFromPropertyAssignment12` test case).

Instead of changing the signature resolution, the error is explicitly
generated in `resolveCallExpression` for those functions.
2018-07-31 13:52:39 -07:00
Andy
0d1a49c865 Ignore trailing comma when resolving signature for quick info (#25841)
* Ignore trailing comma when resolving signature for quick info

* Add test for signature help
2018-07-31 11:39:39 -07:00
Nathan Shively-Sanders
a21ac11582 In JSDoc, resolve import types as values too (#26066)
* In JSDoc, resolve import types as values too

This is something that we probably should have been doing for some time.
Fixes #26049

* Fix whitespace lint
2018-07-31 11:07:06 -07:00
Anders Hejlsberg
4bc7f1570b Merge pull request #26063 from Microsoft/mappedTypesArraysTuples
Improved mapped type support for arrays and tuples
2018-07-31 10:54:44 -07:00
Nathan Shively-Sanders
4d84bde9b3 Only bind module.exports if no local definition exists (#25869)
* Only bind module.exports if no local definition exists

Note that this uses `lookupSymbolForNameWorker`, which is really a
best-effort check since it only knows about symbols that it has already
encountered.

As a side-effect, even when `module` is bound as part of a
`module.exports` reference, it only declares it once instead of one
declaration per reference.

* Only type module.exports inside module files

It is an error inside script files, but the binder sometimes creates a
ModuleExports symbol because we doesn't know whether we have a commonjs
module until after binding is done.

* Only bind module.exports in a commonjs module

Note that this, too, is a best-effort check since evidence of
commonjs-ness may be found after a *reference* to module.exports. (A
reference to module.exports alone is not enough evidence that a file is
commonjs. It has to have an assignment to it.)
2018-07-30 12:27:59 -07:00
Anders Hejlsberg
32a9ec6c30 Add tests 2018-07-29 15:25:54 -07:00
Tim Schaub
960800d1fe Remove trailing whitespace from JSDoc comments 2018-07-28 10:36:10 -06:00
Nathan Shively-Sanders
25fb5419c0 Support the JSDoc @enum tag (#26021)
* Support the JSDoc @enum tag

`@enum` is used on a variable declaration with an object literal
initializer. It does a number of things:

1. The object literal has a closed set of properties, unlike other
object literals in Javascript.
2. The variable's name is resolvable as a type, but it just has the
declared type of the enum tag.
3. Each property's type must be assignable to the enum tag's declared type,
which can be any type.

For example,

```js
/** @enum {string} */
const Target = {
  START: "START",
  END: "END",
  MISTAKE: 0, // error 'number' is not assignable to 'string' -- see (3)
}

Target.THIS_IS_AN_ERROR; // See (1)
/** @type {Target} See (2) */
var target = Target.START;
```

* Fix lint, add new test case, update API baselines
2018-07-28 07:53:08 -07:00
Andy
5e1872f0c0 getDocCommentTemplateAtPosition: Return result if in empty comment (#26026) 2018-07-27 17:34:16 -07:00
Andy
d40d54984e Support deleting all unused type parameters in a list, and deleting @template tag (#25748)
* Support deleting all unused type parameters in a list, and deleting @template tag

* Support type parameter in 'infer'
2018-07-27 11:55:31 -07:00
Andy
3bfe91cdd8 navigationBar: Fix bug for shorthand ambient module (#25992) 2018-07-26 17:27:12 -07:00
Andy
af3f737451 Fix bug for isValidTrigger when contextToken is undefined (#25993) 2018-07-26 17:26:58 -07:00
Andy
0e5af11625 Fix bugs for go-to-definition on mapped type method (#25991) 2018-07-26 17:26:41 -07:00
Andy
0227997fa5 Use import().T for import completions/fixes of pure types in JS files (#25852)
* Use `import().T` for import completions/fixes of pure types in JS files

* Don't call tryUseExistingNamespaceImport if position undefined
2018-07-26 16:16:57 -07:00
Wesley Wigham
d590d5bd0c Remove extraneous const, fixing #25714 (#25982) 2018-07-26 14:43:00 -07:00
Wesley Wigham
d17efe69d1 Fix #25954 - Always retain export modifier if default modifier is present (#25974)
* Fix #25954 - Always retain export modifier if default modifier is present

* Also fix an issue with scope markers in ambient modules not affecting the modifiers required
2018-07-26 12:39:03 -07:00
Mohamed Hegazy
3057be3a0b Merge pull request #25966 from ajafff/shorthandPropertyAssignment-initializer-symbol
correctly resolve Symbol of destructuring shorthand intializer
2018-07-26 09:32:39 -07:00
Klaus Meinhardt
d282c75e73 add quickinfo test 2018-07-26 18:09:51 +02:00
Andy
5e94cf626b Expand span of @typedef with properties to include the @typedef tag (#25950) 2018-07-26 08:56:24 -07:00
Anders Hejlsberg
7473772291 Merge pull request #25938 from Microsoft/fixRestTupleArityCheck
Fix rest tuple arity check
2018-07-25 14:40:57 -07:00
Anders Hejlsberg
1aa2b15f8c Add regression test 2018-07-25 12:42:47 -07:00
Andy
bd600cfd50 Fix duplicate "this" completion (#25900) 2018-07-25 12:29:28 -07:00
Andy
d60f4988a6 In getPropertySymbolsFromContextualType, use union discriminant to filter types (#25914) 2018-07-25 11:53:20 -07:00
Nathan Shively-Sanders
9658b476c2 Fix inferFromUsage on index signatures (#25934)
* Fix inferFromUsage on index signatures

1. Check the argumentExpression to determine the index signature type.
Previously, the code mistakenly checked the type of the element access
itself, which never returned a good type.
2. If inference for the index signature type fails, substitute anyType.
Previously, the code would create a bad index signature with an
undefined type.
3. Add tests. Previously, there were no tests.

* Fixing (1) means that number index signatures are now created.
Previously, only string index signatures would be created.
* Fixing (2) means that index signatures will be inferred from single
usage like `return a[0]`. Previously, the refactoring would fail,
perhaps because of a check when stringifying the index signature (I
haven't tracked down why.)

* Update fourslash test with improved inference
2018-07-25 10:51:11 -07:00
Anders Hejlsberg
7b4d13c95c Merge pull request #25859 from Microsoft/optimizePrimitiveIntersections
Optimize creation of intersections of union types
2018-07-25 10:28:43 -07:00
Anders Hejlsberg
dd4fd8c60e Merge pull request #25913 from Microsoft/fixCircularConstraintCheck
Fix circular constraint check
2018-07-25 06:46:51 -07:00
Andy
e4d4b0ae4b Handle PropertyAssignment in getCommentOwnerInfo (#25911) 2018-07-24 17:43:46 -07:00
Wesley Wigham
23eb591e01 Lookup files by resolved Path and not by fileName in sourcemapDecoder when querying program (#25908)
* Check if the file returned by the program actually refers to the same file as we intend

* Simplify
2018-07-24 15:44:22 -07:00
Anders Hejlsberg
aeae05eaf5 Add regression test 2018-07-24 15:33:02 -07:00
Mohamed Hegazy
870c55c7a5 Merge pull request #25863 from mattmccutchen/issue-9744
Report a semantic error for an arrow function with a "this" parameter.
2018-07-24 15:08:26 -07:00
Wesley Wigham
797d8bd07b Call toPath on sourceRoot to ensure it is always absolute (#25838)
* Call toPath on sourceRoot to ensure it is always absolute

* Leave canonicalization to avoid a Path/string union
2018-07-24 14:14:41 -07:00
Wesley Wigham
59854bbd55 Inspect all possible module paths when looking for the best one to create a specifier with (#25850)
* Inspect all possible specifier paths when looking for the best one

* Add missing secondary option from test
2018-07-24 13:56:21 -07:00
Andy
30c41492d9 moduleSpecifiers: Allow "*" as a path mapping (#25881) 2018-07-23 17:11:30 -07:00
Matt McCutchen
f72193eedc Report a semantic error for an arrow function with a "this" parameter.
Fixes #9744.
2018-07-23 10:42:56 -04:00
Anders Hejlsberg
303e08fc4f Add regression test 2018-07-21 12:31:24 -07:00
Andy
3d672d9550 Ensure fixSpelling and importFixes still trigger on "Did you mean the instance/static member ..." (#25847) 2018-07-20 16:51:35 -07:00
Anders Hejlsberg
7c512fbc41 Merge pull request #25817 from Microsoft/fixGenericRestTypes
Fix generic rest types
2018-07-20 10:57:21 -10:00
Andy
e103692f32 Don't report quickInfo inside a comment in a PropertyAccessExpression (#25813) 2018-07-20 11:49:21 -07:00
Andy
bcd565287c Remove bad import completions tests (#25816) 2018-07-20 11:11:03 -07:00
Nathan Shively-Sanders
31d599abaf Check module.exports (#25732)
* Revert "Revert "Explicitly typed special assignments are context sensitive (#25619)""

This reverts commit 16676f2707.

* Revert "Revert "Explicitly typed prototype assignments are context sensitive (#25688)""

This reverts commit ff8c30d636.

* Initial, wasteful, solution

It burns a check flags. Probably necessary, but perhaps not.

I haven't accepted baselines, but they are a bit questionable. I'm not
sure the synthetic type is right, because I expected to see
{ "exports": typeof import("x") } but instead see { "x": typeof
import("x") }.

* Update some baselines

* module.exports= always uses lhs type

Conflicts between exports property assignments and exports assignments
should get a union type instead of an error.

* Fix lint and accept good user baselines

* Add tests based on user tests.

These currently fail.

* Fix all but 1 of user test bugs found by typing module.exports

Still quite messy and full of notes

* Follow merged symbols+allow any object type

This allows exports like `module.exports = new EE` to have properties
added to them.

Still messy, but I'm going to run user tests and look for regressions.

* Update improved user baselines

* Fix infinite recursion when checking module.exports

* Fix bogus use-before-def error

getExportSymbolOfValueSymbolIfExported should always merge its returned
symbol, whether it's symbol.exportSymbol or just symbol.

* Update user test baselines

* Cleanup

* More small cleanup

* Bind `module` of `module.exports` as a special symbol

Previously it was also special, but created during name resolution in
the checker. It made sense when there was only one special symbol for
all files, but now there is one `module` symbol per file.
2018-07-20 10:59:26 -07:00
Wenlu Wang
fedcd3a1b4 improve completions keyword for function like body (#25824) 2018-07-20 08:25:16 -07:00
Anders Hejlsberg
b48910413a Add regression test 2018-07-19 18:29:30 -07:00