8171 Commits

Author SHA1 Message Date
Wesley Wigham
f6af618ab9
Still generate signatures in SkipContextSensitive mode just to match on return types (#25937)
* Still generate signatures in SkipContextSensitive mode just to match on return types

* Add cache for context-free type of a signature node

* Accept post-merge baseline
2018-08-09 10:17:50 -07:00
Anders Hejlsberg
01f6093a9c
Merge pull request #26143 from mattmccutchen/issue-26130
Have getAssignmentReducedType use the comparable relation instead of typeMaybeAssignableTo.
2018-08-09 07:43:46 -07:00
Anders Hejlsberg
20ebe1eb2b
Merge pull request #26244 from Microsoft/fixThisAndContextualTypes
Revise logic that computes the contextual type for a parameter
2018-08-09 06:07:11 -07:00
Ryan Cavanaugh
6210b7db54
Merge pull request #26245 from Kingwl/fix-compiler-crash
fix compiler crash (#26209)
2018-08-08 11:12:16 -07:00
Andy
1a05f13aef
moveToNewFile: Don't remove empty named imports (#26265) 2018-08-07 12:54:46 -07:00
Andy
794f3a5e76
goToTypeDefinition: Go to function return type (#25952)
* goToTypeDefinition: Go to function return type

* Add more tests

* If a function returns 'void' or some other type with no definition, just return the function definition.
2018-08-07 12:54:19 -07:00
Andy
eaf0d59d35
Fix bug: symbol.valueDeclaration not guaranteed to be defined (#26267) 2018-08-07 12:13:45 -07:00
王文璐
639190d607 fix compiler crash (#26209) 2018-08-07 10:09:26 +08:00
Andy
937afab4b0
Support signature help for contextual parameter type (#26022) 2018-08-06 16:46:30 -07:00
Anders Hejlsberg
eeb19c1e22
Merge pull request #26236 from Microsoft/fixCircularReturnType
Fix circular return type issue
2018-08-06 16:38:31 -07:00
Anders Hejlsberg
9d71023b5c Add fourslash tests 2018-08-06 16:33:21 -07:00
Andy
d0ed21cad1
completions: 'true' and 'false' are type keywords (#26237) 2018-08-06 12:42:56 -07:00
Klaus Meinhardt
7299bceafb infer number index signature in JS object literals (#26221)
Fixes: #26208
2018-08-06 11:52:51 -07:00
Anders Hejlsberg
cfa29ae2fa Merge branch 'master' into fixCircularReturnType
# Conflicts:
#	src/compiler/diagnosticMessages.json
2018-08-06 10:53:20 -07:00
Anders Hejlsberg
6a17f4d162 Merge branch 'master' into fixCircularReturnType
# Conflicts:
#	tests/baselines/reference/recursiveResolveDeclaredMembers.types
#	tests/baselines/reference/typeGuardsWithInstanceOfByConstructorSignature.types
2018-08-06 10:42:35 -07:00
Alexander T
37b9a6bca4 25840 - Add a more meaningful error message to the case when calling a public static method on an instance (#25922)
* add a more meaningful error message to the case when calling a public static method on an instance

* Fix tests
2018-08-06 10:24:48 -07:00
Anders Hejlsberg
efdbbd1cf3 Add regression tests 2018-08-06 10:02:33 -07:00
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
Matt McCutchen
d45e422b46 Have getAssignmentReducedType use the comparable relation instead of
typeMaybeAssignableTo.

typeMaybeAssignableTo decomposed unions at the top level of the assigned
type but didn't properly handle other unions that arose during
assignability checking, e.g., in the constraint of a generic lookup
type.

Fixes #26130.
2018-08-01 23:26:17 -04: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