Commit graph

2169 commits

Author SHA1 Message Date
Anders Hejlsberg d9ee86723a
Merge pull request #29740 from Microsoft/fixCircularMappedArrayTuple
Fix issues related to circular mapped array and tuple types
2019-02-06 13:24:19 -08:00
Anders Hejlsberg 7c096576bc
Merge pull request #29756 from Microsoft/fixStrictPropertyInitialization
Revert change to strict property initialization checks
2019-02-05 15:10:30 -08:00
Anders Hejlsberg 2d44a40202 Add regression test 2019-02-05 13:08:18 -08:00
Ryan Cavanaugh 1ec8a71949
Merge pull request #29711 from jack-williams/switch-on-unknown
Fix #29710: Narrow unknown in switch
2019-02-05 09:08:52 -08:00
Anders Hejlsberg bee9f1a5e7 Add regression tests 2019-02-04 17:48:53 -08:00
Ron Buckton 55762271af
Merge pull request #29695 from Microsoft/fixDtsTypeReferenceEmit
Fix type reference dts emit failure
2019-02-04 13:03:07 -08:00
Jack Williams 3d0c7f3156 Narrow unknown in switch 2019-02-03 16:07:21 +00:00
Anders Hejlsberg 332861b4fc Add tests 2019-02-02 09:37:52 -08:00
Ron Buckton 4b84f56b21 Fix type reference dts emit failure 2019-02-01 16:09:17 -08:00
Klaus Meinhardt 782622f9cd clarify error message for 'readonly' type operator 2019-01-31 19:44:49 +01:00
Klaus Meinhardt f4747f4667 Merge branch 'master' of github.com:Microsoft/TypeScript into add-to-types2 2019-01-31 11:25:01 +01:00
Anders Hejlsberg 96706a75ed
Merge pull request #29510 from Microsoft/constContexts
Const contexts for literal expressions
2019-01-30 15:55:47 -08:00
Ryan Cavanaugh 0df89cc96f
Merge pull request #26941 from jack-williams/narrow-unknown-with-triple-equals
Fix #25172: Add narrowing for `unknown` with triple equals
2019-01-29 16:43:50 -08:00
Anders Hejlsberg 08fe06f527 Merge branch 'master' into constContexts
# Conflicts:
#	src/compiler/checker.ts
2019-01-29 12:29:30 -08:00
Anders Hejlsberg e290559057 Add tests for decorators and declaration emit from error free source 2019-01-26 14:57:02 -08:00
Anders Hejlsberg 4706a060a5 Merge branch 'master' into readonlyArrayTuple 2019-01-26 14:44:15 -08:00
Klaus Meinhardt 6eb83650ea Merge branch 'master' into add-to-types2 2019-01-25 16:56:11 +01:00
Jack Williams 36cc154985 Narrow to any primitive or object and update tests 2019-01-25 09:41:34 +00:00
Jack Williams 1f2338bd78 Update test file and baselines 2019-01-25 09:41:34 +00:00
Jack Williams 267e5989cd Add narrowing for unknown with strict equal 2019-01-25 09:41:34 +00:00
Ryan Cavanaugh 16b6706ee1
Merge pull request #29463 from jack-williams/check-in-expression-with-union
Fix #29457
2019-01-24 13:07:22 -08:00
Anders Hejlsberg 2e94f47602 Add tests 2019-01-19 10:34:38 -08:00
Pranav Senthilnathan d38c616e29
Fix resolution of properties from prototype assignment in JS (#29302)
* fix type derived from prototype assignment

* accept new baselines

* remove direct intersection with object literal assigned to prototype

* add tests

* change webpack submodule commit

* fix submodule commits

* comment and simplify getJSDocTypeReference

* remove circularity guards that aren't hit anymore
2019-01-18 16:00:18 -08:00
Anders Hejlsberg 2200d35385 Add tests 2019-01-18 09:34:38 -08:00
Jack Williams 5651789629 Fix #29457
Use allTypesAssignableToKind instead of isTypeAssignableToKind to
account for union types.
2019-01-17 20:03:46 +00:00
Wesley Wigham 045a450972
Merge branch 'fix-generic-types-intersections' of git://github.com/flapenguin/TypeScript into flapenguin-fix-generic-types-intersections 2019-01-17 10:49:04 -08:00
Anders Hejlsberg 0eac506fc0 Add .d.ts generation test 2019-01-16 12:45:33 -08:00
Anders Hejlsberg 2ccc106984 Add more tests 2019-01-16 09:46:28 -08:00
Wesley Wigham 41a7bf4b73
Fake up value declaration for synthetic jsx children symbol so they get excess property checked (#29359) 2019-01-15 22:31:57 -08:00
Kagami Sascha Rosylight d8ac9ba414
Merge branch 'master' into es2019 2019-01-16 10:54:46 +09:00
Anders Hejlsberg cff7874288 Add tests 2019-01-15 14:44:57 -08:00
Ron Buckton 5763e2c3d4 Remove overzealous simple relationship check for unique symbols 2019-01-14 17:08:04 -08:00
Gabriela Britto e5708e1903
Merge pull request #29352 from Microsoft/qualified-name-param-tag-error
Qualified name param tag error
2019-01-14 10:28:08 -08:00
Martin Probst f3f5877c5f Add tests for noLib with <reference lib> and bundling. 2019-01-11 09:02:49 +01:00
Martin Probst cc7ddaed28 Add tests for noLib with <reference lib>. 2019-01-11 09:02:49 +01:00
Gabriela Britto b3633fab52 Add more tests for qualified name param without top level object error 2019-01-10 15:04:16 -08:00
Gabriela Britto ebe193c6d7 Minor refactor in paramTagNestedWithoutTopLevelObject.ts 2019-01-10 14:05:10 -08:00
Gabriela Britto e2524e3750 Add test for qualified name param without top level object error 2019-01-10 09:55:06 -08:00
Anders Hejlsberg 9fda7014ca Add regression tests 2019-01-09 16:16:24 -08:00
王文璐 34b1384152 add transformer for emit add property to default export 2019-01-03 11:19:02 +08:00
Kagami Sascha Rosylight c89a80736e add ES2019 target 2018-12-27 19:46:21 +09:00
Anders Hejlsberg 7ad2661625 Add tests 2018-12-21 12:51:01 -08:00
Anders Hejlsberg 3e0639add5
Merge pull request #29053 from Microsoft/fixDestructuringControlFlow
Fix destructuring control flow analysis
2018-12-19 11:12:41 -08:00
Anders Hejlsberg 519c501ea5 Add regression test 2018-12-18 11:58:06 -08:00
Anders Hejlsberg 307a9b66af Add tests 2018-12-16 07:23:28 -08:00
Anders Hejlsberg 77d01ab332 Update tests 2018-12-11 15:12:47 -08:00
Anders Hejlsberg 2150a64f0c Add tests 2018-12-11 12:11:16 -08:00
Anders Hejlsberg 45411e525c Add tests 2018-12-10 16:30:30 -08:00
Daniel Rosenwasser 3e6a666b5e
Merge pull request #28919 from a-tarasyuk/feature/28893-allow-trailing-comma-on-tuple-types
feature/28893 allow trailing comma on tuple types
2018-12-10 11:33:33 -08:00
Anders Hejlsberg cd6d2fdc18
Merge pull request #28940 from Microsoft/explicitUnknownConstraint
Type parameter constrained to 'unknown' not assignable to '{}'
2018-12-10 10:29:06 -08:00
Anders Hejlsberg d2cc282134 Add tests 2018-12-10 09:45:55 -08:00
Anders Hejlsberg 7a0779288f Add tests 2018-12-10 09:14:41 -08:00
Alexander e219b17ff0 TupleType - add additional tests to handle error on extra comma 2018-12-08 20:50:09 +02:00
Anders Hejlsberg 4ae0848bd4 Add tests 2018-12-05 15:20:21 -08:00
Anders Hejlsberg 3e2f130b3c Add regression test 2018-12-04 13:18:04 -08:00
Anders Hejlsberg d832fbf46a Add regression test 2018-11-28 14:58:11 -08:00
Andrey Roenko bea7ed1aa7 Merge branch 'master' into fix-generic-types-intersections 2018-11-20 20:31:02 +03:00
Wesley Wigham 96937fd592
Allow union signatures to merge when they have differing argument counts (#28604)
* Allow union signatures to merge when they have differing argument counts

* Accept updated baselines

* Adjust comments io changed tests
2018-11-19 17:05:28 -08:00
Nathan Shively-Sanders 0774bb81ce
Fix crash on property assignment of unresolved module (#28606)
Previously, the compiler would crash when binding a non-top-level
property assignment on the symbol of an unresolved module:

```js
import x from 'arglebaz'
{
    x.bar = 1
}
```

That's because `x` looks like an alias but doesn't have a
valueDeclaration (since there is no file named 'arglebaz'), and the new
code for binding Object.defineProperty calls forgot to check for an
undefined valueDeclaration.

This change adds the checks for an undefined valueDeclaration.
2018-11-19 13:29:46 -08:00
Andy e0dca0bd95
Error when destructuring private property in a parameter (#28562) 2018-11-16 12:47:05 -08:00
Nathan Shively-Sanders 53bb4e84a2
Better checking of assignment declarations (#28387)
Previously, type checking was turned off for all assignment
declarations. This is a problem when the declarations are annotated with
jsdoc types.

This PR checks assignment declarations, *except* for expando
initialisers. Expando initialisers are

1. Empty object types.
2. Function types.
3. Class types.
4. Non-empty object types when the assignment declaration kind is
prototype assignment or module.exports assignment.
2018-11-15 08:46:11 -08:00
Anders Hejlsberg 627f1ad876 Add regression tests 2018-11-09 06:45:21 +01:00
Anders Hejlsberg 48c0aedf54 Add tests 2018-11-02 08:20:06 -07:00
Anders Hejlsberg 8e4b90da00
Merge pull request #28234 from Microsoft/genericSpread
Generic spread expressions in object literals
2018-10-31 12:52:16 -07:00
Anders Hejlsberg 2ed627aaf1 Update tests 2018-10-30 16:33:14 -07:00
Klaus Meinhardt 1397fed2ad Only suggest adding to types if present in compilerOptions
Fixes: https://github.com/Microsoft/TypeScript/pull/28211#issuecomment-434438407
2018-10-30 21:31:22 +01:00
Anders Hejlsberg e0d210d027 Add tests 2018-10-30 08:18:18 -07:00
Nathan Shively-Sanders 64ff195426
Set-only accessors spread to undefined (#28213)
* Set-only accessors spread to undefined

Previously they were skipped. The runtime behaviour is to create a
property of type undefined, unlike (for example) spreading numbers or
other primitives. So now spreading a set-only accessor creates a
property of type undefined:

```ts
const o: { foo: undefined } = { ...{ set foo(v: number) { } } }
```

Notably, `o.foo: undefined` not `number`.

Fixes #26337

* Fix isSpreadableProperty oversimplification
2018-10-29 14:51:12 -07:00
Anders Hejlsberg ccc16136b2
Merge pull request #28170 from Microsoft/fixGenericMappedTypeConstraint
No constraint for { [P in K]: XXX } where K is type variable
2018-10-26 16:02:17 -07:00
Anders Hejlsberg 24e3745296 Add regression test 2018-10-26 15:32:10 -07:00
Andy 36dfd775b3
Parse an object literal property as shorthand unless followed by '(' or ':' (#28121) 2018-10-26 15:00:31 -07:00
Nathan Shively-Sanders dc9a066f65
Do not merge commonJS exports into an alias (#28133)
* Do not merge commonsjs exports onto an alias

getCommonJSExportEquals merges export assignments and export property
assignments. Something like this, which has no equivalent structure in
TS:

```js
module.exports = function() { }
module.exports.expando = 1
```

However, it is sometimes called with an alias, when its
parent, resolveExternalModuleSymbol, is called with dontResolveAlias:
true, and when the initialiser of the export assignment is an alias:

```js
function alias() { }
module.exports = alias
module.exports.expando = 1
```

In this case, (1) the actual value `alias` will have already merged in a
previous call to getCommonJSExportEquals and
(2) getTypeOfSymbol will follow the alias symbol to get the right type.
So getCommonJSExportEquals should do nothing in this case.

This bug manifests in the code for dynamic imports, which calls
getTypeOfSymbol on the incorrectly merged alias, which now has enough
value flags--Function, for example--to take the wrong branch and
subsequently crash.

* Update baselines
2018-10-25 15:08:06 -07:00
Wesley Wigham 0c36266706
Obey the excludeArgument parameter when checking JSX signature validity (#28002)
* Obey the excludeArgument parameter when checking JSX signature validity

* Fix conditional type extending any contextual types and accept baselines

* use flag check to also drop unknown from comparison for the same reason

* Slight refinement - make an intersection to ensure parameter constraints flow through contextual types when instantiated

* Format ternary more nicely
2018-10-22 16:36:11 -07:00
Wesley Wigham f701daf4e0
Infer over each mapped type constraint member if it is a union (#28006) 2018-10-22 16:33:43 -07:00
Nathan Shively-Sanders bf393ae1cd
Check EOF token to get errors for JSDoc (#28000)
* Check EOF token to get errors for JSDoc

* outputFile instead of noEmit for test
2018-10-19 16:23:34 -07:00
Wesley Wigham 69b1cb5bac
Add new special assignment kinds for recognizing Object.defineProperty calls (#27208)
* Add new special assignment kinds for recognizing Object.defineProperty calls

* Add support for prototype assignments, fix nits

* Fix code review comments

* Add test documenting behavior in a few more odd scenarios
2018-10-19 14:31:55 -07:00
Nathan Shively-Sanders e379aeb151
Fix alias of module.exports->exports->IIFE (#27992)
In JS, when you assign `module.exports = exports` and the entire module is
wrapped in an IIFE, the resulting `export=` symbol, after following
aliases, is the module itself. This results in trying to merge the
file's exports with itself inside `getCommonJsExportEquals`, since it
thinks that it has found new exports, possibly in an object literal,
that need to be merged with the file's exports.

For example:

```js
(function() {
exports.a = 1
module.exports = exports
})()
```
2018-10-19 13:50:38 -07:00
Ryan Cavanaugh b64d08a21b
Merge pull request #27522 from jack-williams/trailing-void-args-are-optional
Fix #4260 : Allow trailing arguments that accept void to be omitted
2018-10-19 10:16:56 -07:00
Nathan Shively-Sanders 8779d4ca88
Fix JS merge crashes from lovefield (#27989)
1. Merge enum with expando.
2. Merge enum member with property assignment.
3. Merge interface-declared method declaration with
prototype-property-assignment method declaration.

The reason that the enum merges crash is that getTypeOfSymbol assumes
that symbol flags are (basically) mutually exclusive. This assumption is
shredded, badly, for JS merges.

One fix is to drop the assumption of exclusivity and instead order cases
by least to most likely. This has the highest chance of working, but is
also slow, since you would prefer to order cases by most likely *first*,
not *last*.

The other fix, which is what I did here, is to add a last-chance
re-dispatch at the bottom of
`getTypeOfVariableOrParameterOrPropertyWorker`. This dispatch uses the
valueDeclaration instead of the symbol flags.
2018-10-19 09:23:05 -07:00
Jack Williams 8500f7ce20 Merge branch 'master' into trailing-void-args-are-optional 2018-10-18 19:22:18 +01:00
Wesley Wigham 7b5ef64e76
Unify JSX And Normal Call Checking Codepaths (#27627)
* Unify JSX Call Checking Codepaths

* Add tests for fixed issues

* Fix lint, move all error checking into the only-run-once resolveSignature call

* Remove unused (unreachable?) code path

* Consolidate a little more duplicated logic into signature checking

* Fix #19775 a bit more

* Cosmetic changes from CR
2018-10-16 20:16:00 -04:00
Anders Hejlsberg 04fd365ec3
Merge pull request #27911 from Microsoft/fixCircularMappedType
Fix circular mapped type instantiations for arrays and tuples
2018-10-15 15:51:31 -07:00
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
Anders Hejlsberg 0c3221c220 Add regression test 2018-10-15 10:24:00 -07:00
Andrey Roenko 15b4af63dd #27716: fix protected methods for intersection fo generic classes 2018-10-12 18:23:07 +03:00
Sheetal Nandi c0729a22fd Use string/number signature to get contextual type
Fixes #26587
2018-10-11 15:12:13 -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
Anders Hejlsberg 22907bfb07 Add tests 2018-10-10 15:40:12 -07:00
Anders Hejlsberg 209f30c2f1 Update test 2018-10-08 16:46:45 -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
Nathan Shively-Sanders b185784708 Only functions can be constructor functions (#27369)
`@constructor` put on anything incorrectly makes it a JS constructor. This
is a problem for actual constructors, because getJSClassType doesn't
work on actual classes. The fix is to make isJSConstructor require that
its declaration is a function.
2018-10-08 10:14:31 -07:00
Nathan Shively-Sanders a4a5b3806e Report circular JSDoc type references (#27404)
JSDoc types references can often be to values, which can often be
circular in ways that types tied to declarations cannot. I decided to
create a separate property on SymbolLinks rather than reusing
declaredType, although I'm not sure that's strictly required.
2018-10-08 08:56:29 -07:00
Anders Hejlsberg 62aeeadd1b Merge branch 'master' into fixUnionOfTupleIndexing
# Conflicts:
#	src/compiler/checker.ts
2018-10-06 18:21:23 -07:00
Anders Hejlsberg d4f480cbbb Add tests 2018-10-06 17:03:19 -07:00
Ron Buckton 85a3475df8
Merge pull request #26707 from mprobst/async-super-rename-safe
Per-property super accessors in async functions.
2018-10-05 17:20:21 -07:00
Wesley Wigham 07dbd8be21
Discriminate jsx contextual types same as object contextual types (#27408)
* Discriminate jsx contextual types same as object contextual types

* Extract core discrimination algorithm to getDiscriminationResultForProperty

* Merge all discrimination implementations

* Fix lints
2018-10-05 15:11:12 -07:00
Nathan Shively-Sanders c080324974
Elt access assignment uses declared, not narrowed type (#27574)
I forgot to do this in #26424.

Fixes #27557
Fixes #27412
2018-10-05 11:30:10 -07:00
Wesley Wigham e1d346ea53
Infer tuples for jsx children if contextually typed by a tuple (#27409) 2018-10-04 17:56:38 -07:00