25475 Commits

Author SHA1 Message Date
Anders Hejlsberg
9767522ca0
Merge pull request #27695 from Microsoft/mixedDiscriminantTypes
Allow non-unit types in union discriminants
2018-10-15 13:10:27 -07:00
Nathan Shively-Sanders
c184184713
Add getEffectiveConstructSignatures (#27561)
* Add helpers that understand constructor functions

* getEffectiveConstructSignatures gets construct signatures from type, and
  call signatures from constructor functions if there are no construct
  signatures.
* getEffectiveConstructSignatureReturnType gets the "JS Class type" for
  constructor functions, and the return type of signatures for all other
  declarations.

This is a first step toward making constructor functions have construct
signatures instead of call signatures, which will also contribute to
fixing instantiation of generic constructor functions, which is basically
broken right now.

Note that the baselines *improve* but, because of the previously
mentioned generic problem, are still not correct. Construct signatures
for constructor functions and generic constructor functions turns out to
be an intertwined problem.

* Correct correct originalBaseType

And, for now, return anyType for generic constructor functions used as
base types. Don't give an incorrect error based on the function's return
type, which is usually void.

* Add error examples to tests

* Add construct signatures instead of getEffective* functions

* Fix typo in baseline

* Remove pesky newline

I thought I got rid of it!

* Test of constructor tag on object literal method

It doesn't work, and shouldn't in the future, because it's a runtime
error.
2018-10-15 12:47:57 -07:00
TypeScript Bot
bb275b999c Update user baselines (#27905) 2018-10-15 08:08:33 -07:00
Andy
54a5be1860
At '.' in object literal, don't close the object (#27850)
* At '.' in object literal, don't close the object

* Include diagnostics test
2018-10-12 08:49:04 -07:00
Sheetal Nandi
12cd3ea6ac
Merge pull request #27849 from Microsoft/unionWithIndexedLiteral
Use string/number signature to get contextual type
2018-10-11 17:50:16 -07:00
Nathan Shively-Sanders
ec0e8cbe2b
noImplicitAny as suggestion (#27693)
* noImplicitAny as suggestion

Note that not all noImplicitAny errors turn into suggestions. In
particular,

1. reportErrorsFromWidening does not, because it doesn't log an error
that infer-from-usage fixes, and fixing it would require
otherwise-unnecessary code.
2. auto types do not have implicit any suggestions, because that would
require running control flow in noImplicitAny mode.

* Rename reportImplicitAny+forbid it for non-checkJS

In JS, you only get implicit any errors/suggestions with checkJS or
ts-check turned on.

* Update baselines

* Use isCheckJsEnabledForFile

* Remove noImplicitAny parameter since it's in scope already
2018-10-11 16:15:38 -07:00
Sheetal Nandi
99b271853a
Merge pull request #27844 from Microsoft/includeJson
Allow files to be included by `*.json` pattern in include of tsconfig
2018-10-11 15:48:44 -07:00
Sheetal Nandi
9cda8d61fa
Merge pull request #27714 from Microsoft/okToSkipJsonOverrite
Skip writing json file if it is going to overwrite same location
2018-10-11 15:48:28 -07:00
Matt McCutchen
d19fb98ec6 When instantiating a mapped type, clone the type parameter. (#27597)
This gives the type parameter returned by getTypeParameterFromMappedType
an accurate constraint.

Fixes #27596.
2018-10-11 15:45:51 -07:00
Sheetal Nandi
c0729a22fd Use string/number signature to get contextual type
Fixes #26587
2018-10-11 15:12:13 -07:00
Sheetal Nandi
92f3f1cde0 Allow files to be included by *.json pattern in include of tsconfig
Fixes #25636
2018-10-11 14:45:27 -07:00
Nathan Shively-Sanders
4d504f9b30
assertNever special-cases nodes with SyntaxKind (#27712)
* assertNever special-cases nodes with SyntaxKind

* Fix single-quote lint

* Use stringify when not a node
2018-10-11 12:33:29 -07:00
Anders Hejlsberg
5a126e2b27
Merge pull request #27587 from Microsoft/fixUnionOfTupleIndexing
Fix indexing and destructuring of unions of tuple types
2018-10-11 12:01:24 -07:00
Sheetal Nandi
2787a2793a Skip writing json file if it is going to overwrite same location
Fixes #24715
2018-10-11 11:12:44 -07:00
Sheetal Nandi
6365eb05f4
Merge pull request #27715 from Microsoft/handleEmitDeclarationOnly
Do not generate jsFile path if its emitOnlyDeclarations is set
2018-10-11 11:08:40 -07:00
Sheetal Nandi
0d91838593 Do not generate jsFile path if its emitOnlyDeclarations is set
Fixes #27009
2018-10-11 10:14:59 -07:00
Anders Hejlsberg
b040ea66d1 One more CR fix 2018-10-11 10:13:36 -07:00
TypeScript Bot
d493c47aac Update user baselines (#27710) 2018-10-11 09:58:25 -07:00
Anders Hejlsberg
dd6365615d Address CR feedback 2018-10-11 08:45:47 -07:00
Sheetal Nandi
b2bae85cce
Merge pull request #27609 from Microsoft/betterStaticError
Report the errors for static incompatibility only if instance types are assignable
2018-10-10 15:42:46 -07:00
Sheetal Nandi
3e91652640
Merge pull request #27688 from Microsoft/fixTsBuildIncrementalNoErrorScenario
Remove any existing errors in case of successful build in tsbuild watch mode
2018-10-10 15:42:31 -07:00
Anders Hejlsberg
6cdba6d351 Accept new baselines 2018-10-10 15:40:19 -07:00
Anders Hejlsberg
22907bfb07 Add tests 2018-10-10 15:40:12 -07:00
Anders Hejlsberg
7737cd5f1f Accept new baselines 2018-10-10 15:11:57 -07:00
Anders Hejlsberg
c110f57deb Discriminant must include at least one unit type and no instantiable types 2018-10-10 15:11:35 -07:00
Andy
dd764b318f
importFixes: Skip alias when testing isTypeOnlySymbol (#27674) 2018-10-10 13:45:52 -07:00
Sheetal Nandi
ba0f5581f6 Remove any existing errors in case of successful build in tsbuild watch mode
Fixes #27685
2018-10-10 12:52:34 -07:00
Ryan Cavanaugh
fc788393ab
Merge pull request #26810 from Kingwl/fix_lookup_regression_again_and_again
fix lookup regression again and again
2018-10-10 09:44:37 -07:00
王文璐
20054d9e10 Merge branch 'master' into fix_lookup_regression_again_and_again 2018-10-10 15:24:03 +08:00
Anders Hejlsberg
d0698751ce Allow discriminant property to contain some non-unit types 2018-10-09 18:41:58 -07:00
Sheetal Nandi
07966dcb12
Merge pull request #27643 from Microsoft/simpleTypeMap
Converted legacySafelist to map to avoid using array prototype methods accidently to match with filename
2018-10-09 14:11:10 -07:00
Sheetal Nandi
23ec0c4484 Accept public api change 2018-10-09 13:45:17 -07:00
Sheetal Nandi
51ff0d32da
Merge pull request #27625 from Microsoft/fileAddedWithAmbientModule
Use ambient modules as references to keep track of reporting and usage of modules correctly
2018-10-09 13:43:12 -07:00
Sheetal Nandi
531d58fbea
Merge pull request #27563 from Microsoft/nonPollingWatcher
Ignore the directory watchers invoked in non polling watch mode with no relative file name information
2018-10-09 13:22:34 -07:00
Sheetal Nandi
b4b29ab1e1 Converted legacySafelist to map to avoid using array prototype methods accidently to match with filename
Eg. constructor.js was adding constructor function to aquisition.include which
resulted in the mismatch between typing installer's typeAquisition (which was passed as JSON string and parsed back to null) and one in project
That meant we kept on queuing the new typing installation request.
Fixes #27435
2018-10-09 13:21:43 -07:00
Nathan Shively-Sanders
53906f222f
containsTopLevelCommonjs:handle uninitialised vars (#27642)
Previously it assumed that all variable declarations had an initialiser,
which is not correct.
2018-10-09 13:17:54 -07:00
TypeScript Bot
74392a0e51 Update user baselines (#27632) 2018-10-09 10:42:21 -07:00
Nathan Shively-Sanders
88d3c6fd5f
inferFromUsage codefix now emits JSDoc in JS files (#27610)
* Now adding @type to variable declarations, at least

Probably everything else, but not as well.

* Improve @param output and add test

It's still bad, but at least it's not wrong.

* Add some js/inferFromUsage tests and fixes

Also, remove redundant is(Set|Get)Accessor functions.

* Fix @typedef refactor

* Emit JSDoc optional parameters

By surrounding the parameter name with brackets. It is super, super ugly
right now.

* Get rest of existing tests working

* Correct location of comments

* Handle @param blocks

1. Format multiple params nicely in a single-multiline block.
2. Generate only params that haven't already been documented. Existing
documentation is not touched.

* Re-add isGet/SetAccessor -- it is part of the API

* Move isSet/GetAccessor back to the original location

* Oh no I missed a newline and a space

* Switch to an object type

* A lot of cleanup

More to come, though. annotate is only called in
annotateVariableDeclaration where we don't know whether we're in JS or
not.

* Move and delegate to annotateJSDocParameters

* Address PR comments

* Lint: newline problems!!!!

* Switch another call to getNonformattedText

* Update baseline missed after merge
2018-10-09 10:38:46 -07:00
Andy
1a5e66995a
Don't crash if spawnSync result's stderr is null (#27616) 2018-10-09 09:42:43 -07:00
Sheetal Nandi
585420e9fa Updated callback signature 2018-10-09 08:42:27 -07:00
Nathan Shively-Sanders
ca94d8efd9
Infer from usage better import types (#27626)
* Use host to improve SymbolTracker implementation

* inferFromUsage: Provide a better moduleResolverHost

This produces better paths on import types.
2018-10-09 07:12:09 -07:00
Andy
f6ca10565d
Fix bug: Ensure JSDoc type range is valid (#27343) 2018-10-08 17:09:48 -07:00
Anders Hejlsberg
840214f1ea Accept new baselines 2018-10-08 16:47:10 -07:00
Anders Hejlsberg
209f30c2f1 Update test 2018-10-08 16:46:45 -07:00
Anders Hejlsberg
2e5a39a3ce Error when indexing out of bounds in a tuple or union of tuples 2018-10-08 16:35:03 -07:00
Sheetal Nandi
03a3978d65 Use ambient modules as references to keep track of reporting and usage of modules correctly
Fixes #27585
2018-10-08 15:56:39 -07:00
Andy
dd9b8cab34
Have scanJsDocToken scan keywords (#27162)
* Have scanJsDocToken scan keywords

* Update API
2018-10-08 14:42:51 -07:00
Wesley Wigham
b85e9e1cc1
Use relative module specifiers in error messages if possible (#27441)
* Use relative module specifiers in error messages if possible

* Dont share number
2018-10-08 14:36:37 -07:00
Nathan Shively-Sanders
ca840ee683 Fix name resolution of exports in JS (#27394)
The ad-hoc name resolution rule for `exports` forgets to check the
requested meaning. When `getTypeReferenceType` calls`
resolveTypeReferenceName` with `Type` only in order to give an error
when the program uses a value like a type, it is incorrectly able to
resolve `exports` instead of producing an error. Then this incorrect
symbol gets treated like an alias, which it isn't, causing the assert.

The fix, for now, is to make resolution of `exports` check the requested
meaning so that it only resolves when `Value` is requested. This makes
the above code an error ("Cannot use the namespace 'exports' as a
type."), but I think this is fine for a bug fix. We can decide later if
`exports` should behave like other expandos and be a legal type
reference.

Note that the name actually does resolve correctly, so JS users will get
the desired completions. They'll just have an error to suppress if they
have checkJs on.
2018-10-08 13:01:14 -07:00
Nathan Shively-Sanders
8a4b6e03ab Fix class/constructor-function merge (#27366)
The check for prototype assignment on constructor functions assumes
that the prototype property, if present, comes from an assignment
declaration, such as:

```js
SomeClass.prototype = { /* methods go here */ }
```

In this case, however, when class SomeClass and var SomeClass merge
(because this is allowed), prototype is the synthetic property from
class SomeClass, which has no valueDeclaration.

The fix is to check that prototype has a valueDeclaration before
checking whether the valueDeclaration is in fact a prototype-assignment
declaration.
2018-10-08 12:56:19 -07:00