Commit graph

2721 commits

Author SHA1 Message Date
Eli Barzilay c7bac6f2e6 Avoid getting undefined callSignatures/constructSignatures in getPropertyOfType
e350c357 (#40228) introduced a subtle bug: it switched the flags to an
alias, dropping `SymbolFlags.Property` --- and that makes
`symbolIsValue()` get to the `resolveAlias(symbol)` call, which leads to
`getPropertyOfType()` with`resolved.callSignatures`+`constructSignatures`
being `undefined`.  So initialize them in `setStructuredTypeMembers`
before calling `getNamedMembers()`.

Fixes #42350
2021-02-11 18:56:47 -05:00
Orta Therox 8c5fa5cc91
Revert assignability cases in getNarrowedType (#42231)
* Revert subtype narrowing changes from readonly array PRs

* Adds a test for the change

* More baselines
2021-02-09 15:03:11 -08:00
Anders Hejlsberg e2318217fb
Strip nullable types from 'this' type in inference with optional chain calls (#42536)
* Properly strip nullable types from this type in optional chain calls

* Add regression test
2021-02-03 13:50:23 -10:00
Song Gao 3e28e29c51
fix 38503. (#39716)
* fix 38503.

* trigger test.

* trigger test.

* Move isCallChain

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-02-01 18:34:46 -08:00
Andrew Branch c15f40abfa
Fix discriminant property narrowing through optional chain with null (#42503)
* Fix discriminant property narrowing through optional chain with null

* Accept baselines

* Add tests from Anders
2021-01-29 12:03:42 -08:00
Nathan Shively-Sanders 9dbfaeef2d
Narrow QualifiedName inside typeof (#42540)
Previously this wasn't narrowed at all. Now there is control flow and
code in isMatchingReference.
2021-01-28 15:19:01 -08:00
Nathan Shively-Sanders d2443a5df1
@typedef: Improve error spans from declaration emit (#42501)
* @typedef: Improve error spans from declaration emit

This is a proof-of-concept fix. I think it could be expanded for all of
jsdoc, but I only set it up for jsdoc type aliases. It could use a lot
of polish too.

* track error node in isSymbolAccessible instead

* Switch to using enclosingDeclaration

Remove trueErrorNode

* add test of @callback and @enum

* Better error + fix @enum error

Since enums don't have a name property, you *have* to call
`getNameOfDeclaration` to go looking through the AST for one.
2021-01-28 08:35:05 -08:00
M.Yoshimura 701493fb80
Support top level "for await of" (#37424)
* Support Top Level "for await of".

* Add test cases for top level "for await of".

* Apply suggestions from code review

* add test cases

* remove redundant variables

* fix test baselines

* Update diagnostic message and tests

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2021-01-25 13:40:45 -08:00
Andrew Branch 89c173fddc
Narrow via discriminant property through optional chain (#42450)
* Naive attempt at narrowing via discriminant property through optional chain

* Clean up test
2021-01-25 09:29:51 -08:00
Oleksandr T 1ecf22884f
fix(42166): allow assertion signature for private identifiers (#42176) 2021-01-11 09:25:51 -08:00
Orta Therox 055f363fba
Reverts #39277 removing bundledPackageName (#41499)
* Reverts #39277

* Bring back modeyule resolution for the test runner
2021-01-08 10:55:34 +00:00
Ron Buckton 0d284e6c26
Add support for abstract constructor types (#36392)
* Add support for abstract constructor types

* Add backwards-compatible overloads for creating/updating constructor types

* Reverting use of 'abstract' in lib/es5.d.ts due to eslint issues

* Update baseline due to reverting lib

* Add error for failing to mark an mixin class as abstract

* Fix declaration/quick info for abstract construct signatures
2021-01-07 17:11:14 -08:00
Andrew Branch dbba8b358f
Make optional properties assignable to string index signatures (#41921) 2021-01-07 10:46:55 -08:00
Anders Hejlsberg 9b1718677a
Leading and middle rest elements in tuple types (#41544)
* Support starting and middle rest elements in tuples

* Accept new baselines

* Include all rest arguments in error span

* Accept new baselines

* Fix tests

* Add new tests

* Fix lint errors
2021-01-04 15:12:51 -10:00
Oleksandr T b405fdd2ab
fix(41420): forbid optional chain in extends/implements (#41481) 2021-01-04 15:38:54 -08:00
Ron Buckton 6fac3ddfd4
Fix module resolution for import call emit (#41390) 2021-01-04 15:08:57 -08:00
Oleksandr T 841b1a5bc7
fix(37791): fix incorrect private field access in a computed property name (#38135) 2021-01-04 14:01:54 -08:00
Oleksandr T e108257fb6
fix(41965): fix error in definite assignment assertion context (#41989) 2020-12-30 11:45:18 -08:00
Oleksandr T 303ed3a357
fix(42099): fix JSDoc optional properties declaration emit (#42116) 2020-12-28 13:34:55 -08:00
Oleksandr T a763600cc4
fix(41818): use last JSDoc comment related to host (#41858) 2020-12-18 13:24:58 -08:00
Ron Buckton 4239904517
Report implicit any error for 'yield' result with no contextual type (#41348) 2020-12-18 09:55:33 -08:00
Ron Buckton e789cb1356
Fix single-line comment disrupting return w/optional chain (#42026) 2020-12-17 18:55:09 -08:00
Anders Hejlsberg ee1f262698
Template literal types for template literal expressions (#41891)
* Infer template literal types for template literal expressions

* Update test

* Update another test

* Accept new baselines

* Minor fixes

* Add tests

* Accept new baselines

* Make new TypeFlags internal

* Accept new API baselines

* Ensure template literals assignable to String, Object, {}, etc.

* Add tests
2020-12-11 15:07:37 -10:00
Wesley Wigham 69143ecc5b
Reuse input nodes where possible when serializing jsdoc implements clauses (#41783)
* Reuse input nodes where possible when serializing jsdoc implements clauses

* Whitespace changes, per PR feedback
2020-12-08 12:13:37 -08:00
Wesley Wigham 360958e04c
JSDoc declaration emit should reuse input nodes where possible when serializing typedefs (#41760)
* JSDoc declaration emit should reuse input nodes where possible when serializing typedefs

* Style comments
2020-12-04 13:42:35 -08:00
Anders Hejlsberg cd37a327a7
Fix non-homomorphic mapped type constraint issues (#41807)
* Less aggressive wildcard check, 'keyof any' constraint for 'infer T' in mapped type constraint position

* Accept new baselines

* Add regression tests
2020-12-03 16:36:45 -10:00
Armando Aguirre 143d1104ab
Merge pull request #41703 from a-tarasyuk/fix/41653
fix(41653): Enum Keys in Destructure Prevents ES6 Function Convert with --target ES5
2020-12-03 16:10:51 -08:00
Ron Buckton 324f0469c0
Merge pull request #41791 from microsoft/fix40643
Reuse temp variable scope for converted loop body
2020-12-03 13:33:09 -08:00
Andrew Branch 69bc3f3b0c
Allow type-only imports on ImportEqualsDeclarations (#41573)
* Allow type-only ImportEqualsDeclarations

* Suppress CJS-in-ESM error when type-only

* Add grammar error on import type in import alias

* Update API baselines

* Fix importsNotUsedAsValues with ImportEqualsDeclarations

* Make bad error talk words more good for Daniel. Fixes #41603

* One more error message baseline update

* Update transformer and emitter
2020-12-03 13:27:15 -08:00
Ron Buckton 27dc177f29 Reuse temp variable scope for converted loop body 2020-12-02 18:11:45 -08:00
Wesley Wigham 9f9eed400c
Read the base construct signature from the static base type, not the instance base (#41767) 2020-12-02 13:30:46 -08:00
Anders Hejlsberg 4d6947ae14
Check nested conditional types for non-distributiveness in mapped types with 'as' clauses (#41713)
* Check nested conditional types for non-distributiveness

* Rename to maybeNonDistributiveNameType

* Add regression test
2020-12-01 12:07:47 -10:00
Anders Hejlsberg 4782c74b75
Propagate wildcard types in non-homomorphic mapped types (#41622)
* Propagate wildcard types in non-homomorphic mapped types

* Add regression test

* Accept new baselines

* Accept new baselines
2020-12-01 11:57:00 -10:00
Toan Nguyen 0c76803854
Fix typos in comments (#41307)
* Fix typo fuction -> function

* Fix typo assignement -> assignment
2020-11-30 15:02:07 -08:00
Oleksandr T 3a903b8a28 fix(41653): convert arrow function to function expression that used as destructure initializer 2020-11-26 21:19:15 +02:00
Anders Hejlsberg 411c6d04c6
Fix getTypeFacts for pattern template literal types (#41693)
* Normalize `${string}` to just string, fix getTypeFacts

* Add tests

* Accept new baselines
2020-11-26 06:55:01 -10:00
Nathan Shively-Sanders 9fb6acf1e1
Add missed resolveSymbol in commonjs import resolution (#41479)
Fixes resolution of export aliases in the postfix-property-access case
of commonjs require:

```js
const { x } = require('./foo').nested
x
```

This program would previously fail if `x` was an export alias.

Fixes #41422
2020-11-10 11:28:49 -08:00
Oleksandr T 45b698b3f6
fix(40632): skip emitting abstract members (#40699) 2020-11-04 16:02:17 -08:00
Thomas Williamson 8ed251d0c7
Support xml namespace prefix for JSX elements and attributes (#37421)
* Support xml namespace prefix for JSX elements and attributes

Just as with the `-` character, `:` is now also treated specially in JSX
element and attribute names, but is only allowed a single time, and not
at the beginning or end of the name, as is specified in the JSX spec.
All tests in jsxInvalidEsprimaTestSuite still fail, but for slightly
different reasons now. Two lines in jsxEsprimaFbTestSuite were
uncommented as they included elements with namespaces, and they now pass
without error.

* Add case for colons at ends of identifier

* Add case for jsx namepsace intrinsics

* Add cases with upcase idents for jsx namespaces

* Add case for jsx namespaces with react option

* Always consider jsx names with colon to be intrinsics

* Adjust comment about chars valid in jsx names but not js idents

* Fix minor typo in namespace prefix test case variable name

* Remove misleading comments on isUnhyphenatedJsxName
2020-11-02 15:34:36 -08:00
Wenlu Wang ce8d702586
Add support for pedantic property access (#40171)
* Add support for pedantic property access

* accept baseline

* Update diag message

* Avoid pedantic

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2020-11-02 15:19:00 -08:00
Ron Buckton f944afd053 Fix double alias of complex export/import/default/namespace combination 2020-10-29 18:42:36 -07:00
Ron Buckton bcbe1d7638
Merge pull request #41094 from microsoft/destructuringEvaluationOrder
Fix destructuring evaluation order for initializers
2020-10-29 17:12:18 -07:00
Ron Buckton 2b7e790732 Update control flow for nested binary exprs 2020-10-29 13:32:32 -07:00
Ron Buckton 8a15291541 Update control flow for correct destructuring evaluation order 2020-10-28 16:50:15 -07:00
Wesley Wigham ca8a15d37b
Merge pull request #41287 from weswigham/bind-exports-assigned-object-as-alias
Bind `module.export = {Thing}` with alias symbols
2020-10-28 13:14:20 -07:00
Oleksandr T af38ab90e2
feat(41249): allow import.meta with module: es2020 (#41274) 2020-10-27 17:26:15 -07:00
Anders Hejlsberg 40b81224f9
Remove string literals from unions with matching template literals (#41276)
* Remove string literals from unions with matching template literals

* Add tests

* Accept new baselines
2020-10-27 16:21:07 -07:00
Wesley Wigham d1bc6b1ba6
Bind module.export = {Thing} with alias symbols 2020-10-27 15:43:00 -07:00
Wesley Wigham 94b0e0e389
Merge pull request #41190 from weswigham/handle-binding-element-aliases
Handle the new js binding element alias symbols in JS declaration emit
2020-10-23 10:31:08 -07:00
Ron Buckton 0b303ff08a Fix some rest cases and handling of unused results 2020-10-22 18:58:21 -07:00
Ron Buckton 28c4f32ddf Merge branch 'master' into destructuringEvaluationOrder 2020-10-22 17:14:23 -07:00
Anders Hejlsberg 5d021b401a
Don't reduce 'keyof M' for mapped types with non-distributive 'as' clauses (#41186)
* Don't reduce 'keyof M' for mapped types with non-distributive as clauses

* Add regression test

* Accept new baselines
2020-10-21 12:16:46 -07:00
Wesley Wigham f4255dd237
Handle the new js binding element alias symbols in JS declaration emit 2020-10-21 11:24:19 -07:00
Wesley Wigham 0ad22de146
Merge branch 'master' into fix/create-element-new-jsx-transform 2020-10-19 15:21:52 -07:00
Anders Hejlsberg 4638c685b1
Properly reduce intersections of string literal and template literal types (#41162)
* Properly reduce single element intersections

* Add regression test

* Accept new baselines
2020-10-19 13:05:29 -07:00
Mateusz Burzyński 43433eb2f1 Add tests related to the key prop when using new JSX transform 2020-10-17 15:20:39 +02:00
Ron Buckton 7393dba6bd Fix destructuring evaluation order for initializers 2020-10-13 17:14:35 -07:00
Nathan Shively-Sanders a109b5d5c8
Fix relative paths in commonjs decl emit w/property access (#40986)
```js
const x = require('./foo').y
```

was incorrectly using the unmangled require path as the temp name in
emit:

```
import ./foo_1 = require('./foo')
import x = ./foo_1.y
```

It now uses the imported identifier:

```
import x_1 = require('./foo')
import x = x_1.y
```

Discovered while fixing #37832
2020-10-09 16:32:57 -07:00
Nathan Shively-Sanders 4283428906
Fix export binding of namespaced typedefs (#40980)
The binder incorrectly rejected implicit namespace declarations in
typedefs.
2020-10-07 13:21:02 -07:00
Anders Hejlsberg f34220980b
Add isDeeplyNestedType logic to getResolvedBaseConstraint (#40971)
* Add isDeeplyNestedType logic to getResolvedBaseConstraint

* Accept new baselines

* Add regression test

* Accept new baselines

* Fix lint issue
2020-10-07 05:50:06 -07:00
Simon Chan fc0eed3795
lib: remove length field from SharedArrayBuffer (#40858)
* fix(lib): SharedArrayBuffer does not have a `length` field

* Revert formatting change.

* test: add tests for SharedArrayBuffer.length

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2020-10-06 08:27:56 -07:00
Nathan Shively-Sanders 477e4b1a9d
Fix function merged with export as namespace sourcefile (#40908)
Previously it crashed because the function-checking code didn't expect
a node with no parent.
2020-10-02 10:50:12 -07:00
Nathan Shively-Sanders b8ebad48d7
Fix recursive types in @typedef (#40861)
* Fix reference types in @typedef

Previously this code path was broken and untested. Fortunately the fix
is simple.

* add test case from #40234

* update baselines
2020-10-02 08:46:42 -07:00
Wesley Wigham da86332120
Limit export= js declaration emit to only json source files (#40882) 2020-10-01 14:55:24 -07:00
Wesley Wigham 3ea81e652a
Ensure whitespace jsx elements are not counted when determining if a jsx child is the only child (#40839)
* Ensure whitespace jsx elements are not counted when determining if a jsx child is the only child

* Use filtered children count for deciding constructor used

* Accept updated baselines post-merge
2020-10-01 14:36:44 -07:00
Andrew Branch 5fbe9806db
Fix noUncheckedIndexedAccess with tuple rest types and generic index types (#40681)
* Fix noUncheckedIndexedAccess for tuple rest elements

* Defer inclusion of undefined for generic indexed access types

* Create separate IndexedAccessTypes depending on whether --noUncheckedIndexedAccess applies

* Undo accidental export

* Parenthesize for clearer precedence
2020-10-01 13:56:13 -07:00
Anders Hejlsberg 950dad9c29
Propagate wildcard types in template literal type construction (#40875)
* Propagate wildcard types in template literal type construction

* Add regression test

* Accept new baselines
2020-10-01 13:36:08 -07:00
Anders Hejlsberg 4538e7352f
Properly distribute over unions in keyof for mapped types with as clause (#40837)
* Properly distribute over unions in keyof mapped types with as clause

* Accept new baselines

* Add regression test

* Accept new baselines
2020-10-01 09:36:51 -07:00
Andrew Casey 35111231f7
Merge pull request #40755 from amcasey/SpreadLimit
Enforce a size limit in getSpreadType
2020-09-30 13:44:59 -07:00
Nathan Shively-Sanders f615e229d3
Fix default property assigned prototype (#40836)
* Fix default-property-assignment decls+prototype property decls

The check in getAssignedClassSymbol forgot to allow for default-property
assignment declarations, in part because it wasn't using a utility
function to do so.

* small cleanup

* make allowDeclaration parameter required
2020-09-30 08:36:52 -07:00
Wesley Wigham 2428ade1a9
Match suffix _after_ prefix when inferring literals out of templates (#40841) 2020-09-29 16:34:58 -07:00
Andrew Casey 6650496e85 Enforce a size limit in getSpreadType
When a union is spread into a union, the sizes are multiplied,
potentially resulting in an enormous union (especially if there are
repeated spreads).  This check detects cases that used to run out of
memory.

Fixes #40754
2020-09-24 14:52:42 -07:00
Wesley Wigham a960463cf3
Allow pattern literal types like http://${string} to exist and be reasoned about (#40598)
* Allow pattern literal types like `http://${string}` to exist and be reasoned about

* Allow bigint, number, null, and undefined in template holes

* Add test of the trivia case

* Handle `any` in template holes, add assignability rules for template -> template relations

* Explicitly test concatenated patterns

* PR Feedback
2020-09-23 01:08:58 -07:00
Wesley Wigham ad2a07440c
Fix crash on js declaration emit of export assigned default augmented function (#40596)
* Fix crash on js declaration emit of export assigned default augmented function

* {sp}
2020-09-23 00:50:12 -07:00
Anders Hejlsberg 5d6cce5ca7
Const contexts for template literals (#40707)
* Support const assertions with template literal expressions

* Add tests

* Accept new baselines
2020-09-22 13:11:17 -10:00
Alex T 0310b530d8
feat(40663/40664): improve error messages for assignment assertions '!' (#40669) 2020-09-21 11:20:01 -07:00
Anders Hejlsberg fbce4f6c98
Intrinsic string types (#40580)
* Introduce Uppercase<T> and Lowercase<T> intrinsic types

* Accept new API baselines

* Add Uppercase/Lowercase/Capitalize/Uncapitalize to lib.d.ts

* Update fourslash

* Add an 'intrinsic' keyword

* Update template literal type tests

* Accept new API baselines

* Minor fixes

* Switch Capitalize<T> and Uncapitalize<T> to intrinsic types

* Add tests

* Accept new baselines

* Accept new baselines

* Remove template literal type casing modifiers

* Update tests

* Accept new baselines

* Add more tests

* Normalize nested template literal types

* Add normalization tests

* Accept new baselines

* Update tests
2020-09-21 07:09:29 -10:00
Anders Hejlsberg ce3dbef5f7
Support properties of mapped types in assertion control flow analysis (#40482)
* Support properties of mapped types in assertion control flow analysis

* Add regression test

* Accept new baselines
2020-09-21 07:07:29 -10:00
Anders Hejlsberg 17c7c261d4
Properly preserve modifiers in homomorphic mapped types with 'as' clauses (#40633)
* Use original property name to fetch source property for modifiers

* Add regression test

* Accept new baselines
2020-09-19 06:12:39 -10:00
Hikari Hayashi f1ac8cd93f
Fix children prop for react-jsx and react-jsxdev (#40630)
* Fix children prop for `react-jsx` and `react-jsxdev`

* Add tests
2020-09-18 14:26:20 -07:00
Nathan Shively-Sanders ec36d73e7a
Fix error on duplicate commonjs exports (#40545)
* Fix error on duplicate commonjs exports

Previously, the code missed setting the parent pointer for the lhs
access expression.

Also add declaration emit of element access expressions, missed in my
previous PR.

* Switch to excludes=None, add test case

CommonJS exports have None excludes, but still have an error issued by
the checker. This is the previous behaviour even though it would be nice
to add some exclusions.
2020-09-14 13:12:51 -07:00
Anders Hejlsberg 57c8938d9e
Consistent inferences when inferring to template literal type (#40518)
* Consistently make inferences when inferring to template literal type

* Add tests

* Accept new baselines
2020-09-12 16:33:33 -10:00
Nathan Shively-Sanders 9c99870058
Support element access aliases: exports["x"] = x (#40514) 2020-09-11 18:05:47 -07:00
Anders Hejlsberg eee799fe0c
Properly check types in template literal placeholders (#40498)
* Properly check types in template literal placeholders

* Add regression test

* Update test

* Accept new baselines
2020-09-11 14:48:35 -10:00
Ryan Cavanaugh 3d235b42a0
--noUncheckedIndexedAccess (#39560)
* Initial implementation + tests

* linty

* Support destructuring declarations and assignments

* lint

* Fix destructuring assignment and element access into known properties

* Update baselines

* Rename flag to unUncheckedIndexedAccess

* Add test for unique symbol indexing

* Fix flag order in baselines

Co-authored-by: Andrew Branch <andrew@wheream.io>
2020-09-11 14:43:10 -07:00
Wesley Wigham a36f17c1f8
Add emit support for jsx/jsxs experimental jsx runtime api (#39199) 2020-09-11 10:44:52 -07:00
Andrew Branch 083129f005
A union including non-iterable types is not iterable (#40350)
* WIP

* If method type derives solely from the global iterator or generator type, use its type arguments

* Add test for problem fixed as side effect
2020-09-11 09:31:22 -07:00
Orta Therox cdafb7157b
Replaces the default module index resolver with '/index' instead of '' when handling internal routing for dts bundles (#39277)
* Adds support for declaring the bundled name of a dts module export

Co-authored-by: Wesley Wigham <wwigham@gmail.com>

* Adds baselines

* Update the tests

* Try to reduce the scope of the bundledPackageName error

* Use the flag in more baselines

* Get it green

* More tests

* Handle more feedback

* More test cleanup

* Set the moduleResolution for the tsconfigs

Co-authored-by: Wesley Wigham <wwigham@gmail.com>
2020-09-11 08:12:07 -04:00
Nathan Shively-Sanders 0eb0fb6d72 Change baseline name to avoid case-only conflict
Windows hates this one weird trick! (And humans are mightily confused by
it)
2020-09-10 13:17:40 -07:00
Nathan Shively-Sanders b7c598ea39
Use ad-hoc code for nested destructuring in require (#40188)
* Use ad-hoc code for nested destructuring in require

Nested destructuring doesn't really map to ES imports:

```js
const { utils: { nub, intercalate } } = require('./monopackage')
```

Previously, isRequireVariableDeclaration walked up binding elements
until it reached a variable declaration. This change instead only walks
up one binding element and stops. Then it's not bound as an alias and
uses the checker-only code to produce types for the nested-imported
identifiers.

Fixes #40143

* revert binder formatting change
2020-09-10 13:07:58 -07:00
Nathan Shively-Sanders e350c357d2
Alias for module.exports.x = x (#40228)
* Alias for `module.exports.x = x`

This fixes #40155 in a surprisingly small amount of code.

* Treat any aliasable expression as an alias

* test internal references to exported class
2020-09-10 11:23:48 -07:00
Wesley Wigham 683979246f
Fix JS declaration emit for acessors in a class/interface merge (#40456) 2020-09-10 10:39:41 -07:00
Anders Hejlsberg 6f0c91c4cb
Template literal types and mapped type 'as' clauses (#40336)
* Initial implementation of string template types

* Accept new API baselines

* Accept new baselines

* Unified checking for large cross product union types

* Accept new baselines

* Ensure errors from union type resolution are reported

* Accept new baselines

* Compute constraints for string template types

* Support `as T` clause in mapped types

* Accept new API baselines

* Add missing semicolon

* Add checking of `as T` clauses

* Support casing modifiers in string template types

* Accept new baselines

* Bump keyword maximum length

* fix anders

* Revert "fix anders"

This reverts commit b3178d4618.

* Properly handle 'as T' clause with keyof for mapped type

* Fix lint error

* Single character inferences and anchored end span matching

* Fewer array copy operations in template literal type resolution

* Handle cases where 'as T' maps multiple properties onto one

* Fix lint error

* Store key type instead of type mapper in MappedSymbol

* No constraint on `in T` type when `as N` clause present

* Rename from TemplateType to TemplateLiteralType

* Accept new API baselines

* Add tests

* Accept new baselines

* Address CR feedback

* Accept new API baselines

Co-authored-by: Erich Gamma <egamma@microsoft.com>
2020-09-09 17:23:22 -10:00
Wenlu Wang ee5f51bc0f
Add see tag support (#39760)
* Add see tag parser

* add baseline

* fix symbol resolve

* add more case

* fix unittests

* improve tests and parser

* accept baseline

* Adopt package-lock.json and npm ci

* Add a workflow to update package-lock.json daily

* Git ignore package-lock.json and forcibly update in workflow

* Update bot email address

* Delete extra npm update

* Update package-lock.json

* Add compactDisplay and signDisplay to NumberFormatOptions (#40039)

* Fix typo in (Readonly)Set.keys comment (fixes #40164) (#40176)

* fix(26325): use a unique name for reserved words in 'constructor like' function name (#39684)

* fix(25770): add diagnostic message for the possible mapped type used as an index (#39973)

* fix(31046): add new diagnostic message for incompatible constructor signature (#40073)

* Update package-lock.json

* Update package-lock.json

* Add rename support

* Accpet baseline

* wip

* fix anders

* Revert "fix anders"

This reverts commit b3178d4618.

* Fix call hierarchy item serialization and server tests (#40348)

* Avoid error

* accept baseline

* Add more tests

* Add signature name resolve

Co-authored-by: Andrew Casey <andrew.casey@microsoft.com>
Co-authored-by: TypeScript Bot <typescriptbot@microsoft.com>
Co-authored-by: Neil Kistner <neil.kistner@gmail.com>
Co-authored-by: cherryblossom000 <31467609+cherryblossom000@users.noreply.github.com>
Co-authored-by: Alexander T <alexander.tarasyuk@outlook.com>
Co-authored-by: Erich Gamma <egamma@microsoft.com>
Co-authored-by: Andrew Branch <andrewbranch@users.noreply.github.com>
2020-09-09 10:45:09 -07:00
Alex T 15084465b7
fix(40222): fix crash on using destructuring in a catch clause (#40240) 2020-09-08 11:49:45 -07:00
Orta Therox fa89ce6158
Remove assignability cases in getNarrowedType + an isArray improvement for readonly arrays (#39258)
* Explore using a different isArray declaration

* Add tests and the new isArray definition

* Baseline updates

* Upda the isArray type
2020-09-08 14:43:48 -04:00
Anders Hejlsberg cea1cfb82e
Consistently error when rest element isn't last in tuple type (#40254)
* Consistently error when rest element isn't last in tuple type

* Add regression test

* Accept new baselines

* Stricter circular recursion check in type inference

* Revert "Stricter circular recursion check in type inference"

This reverts commit 80e6df6230.

* Revert "Accept new baselines"

This reverts commit 355706dadc.

* Accept new baselines
2020-09-08 07:14:16 -10:00
Wesley Wigham 155610e114
Better support class instances assigned to the module object for JS declarations (#40037)
* Better support class instances assigned to the module object for JS declarations

* Extract constant
2020-09-05 02:23:12 -07:00
Alexander T 09d68efae1
fix(28516): forbid using async modifier with the abstract modifier (#39963) 2020-09-04 14:59:53 -07:00
Nathan Shively-Sanders b0011feee1
Checkjs implies allowjs (#40275)
* Passing --checkJs always sets --allowJS

Even if you have `"allowJs": false`. This is not a useful combination.

Changing this makes the compiler more friendly and easier to describe.

* only set allowjs if not explicitly set

* remove stray newline

* restore bad config error

* use an accessor function instead
2020-09-01 10:16:08 -07:00
Nathan Shively-Sanders d572dcb272
Fix crash intersecting dynamic import w/esModuleInterop (#40249)
* Fix crash intersecting dynamic import w/esModuleInterop

The dynamic import shim creates a symbol without some properties that
the intersection-creating code assumes are present as of #38673.

This PR adds the smallest possible set of properties to avoid the crash.
I'm not sure what others would be good to add.

* Use symbol's declarations instead

* Fix getResolvedMembersOrExportsOfSymbol instead

* comment from code review
2020-09-01 09:10:36 -07:00
Nathan Shively-Sanders 378083fcec
Nested assignment to a require alias isn't a declaration (#40186)
This is not something we can type correctly, and doesn't work in
Typescript either. Better to ignore it in JS.
2020-09-01 08:20:56 -07:00
Ron Buckton 10fb9c9381
Treat trailing 'void' as optional for assignability (#40231) 2020-08-28 09:12:09 -07:00
Kyℓe Hensel c5446d1a47
don't emit "unused @ts-expect-error" in unchecked js files (#40046)
* don't emit unused ts-expect-error in unchecked js files

* simplify code
2020-08-25 11:04:23 -07:00
Nathan Shively-Sanders 4aadd5af41
Fix commonjs require of ES export (#40221)
The commonjs-specific code for resolving access expressions on `require`
assumes a fake commonjs export. For real exports, it needs to call
resolveSymbol since it's outside the normal alias-resolving
infrastructure.
2020-08-24 12:37:25 -07:00
Ron Buckton 598e9b2e88
Allow trailing params of 'undefined', 'unknown', and 'any' to be optional in non-strictNullChecks JS (#40057) 2020-08-20 13:38:14 -07:00
Nathan Shively-Sanders 55ca5e91b9
Fixes crash on chained property access on require (#40135)
From the user tests:

```js
const x = require('y').z.ka
```

would cause the crash because I forgot to call
getLeftMmostPropertyAccessExpression in one place.

Note that this doesn't fix the alias, it just stops the crash.
2020-08-19 12:59:22 -07:00
Wesley Wigham 44d2350e5f
Fix tuple name homogeneity check (#40118) 2020-08-19 12:08:17 -07:00
Nathan Shively-Sanders c3d41bbb73
Alias for commonjs require in JS (#39770)
* First attempt at aliases for require

* test+initial support for const x=require

* 1st round of baseline improvements

* 2nd round of baseline updates

* support property access after require

* check @type tag on require

* forbid expando missing namespaces on aliases

taken from #39558 as soon as it was created

* accept error baselines that are good, actually

* Scribbling on d.ts emit code

* use getSpecifierForModuleSymbol

* hideous hack for module.exports of aliases

* Fix module.exports.x --> export list emit

* fix isLocalImport predicate

* require only creates aliases in JS

* re-handle json imports

* update fourslash baseline

* Cleanup in the checker

1. Simplify alias resolution.
2. Simplify variable-like checking.
3. Make binding skip require calls with type tags -- they fall back to
the old require-call code and then check from there.

I haven't started on the declaration emit code since I don't know what
is going on there nearly as well.

* Function for getting module name from require call

* First round of cleanup plus a new test

Found one missing feature, not sure it's worth adding.

* more small cleanup

* more cleanup, including lint

* use trackSymbol, not serializeTypeForDeclaration

* Code review comments, plus remove unneeded code

Ad-hoc type reference resolution for `require` isn't needed anymore.

* find all refs works

* remove old ad-hoc code

* make it clear that old behaviour is not that correct

* update api baselines

* remove outdated comment

* PR feedback

1. Fix indentation
2. Add comment for exported JSON emit
3. Add test case for nested-namespace exports.

* add a fail-case test (which passes!)
2020-08-17 14:00:37 -07:00
Eli Barzilay 620e260576 Avoid the double-symbol trick for enums
Nameless jsdoc typedefs have their exportedness controlled by the
exportedness of the location they pull their name from.

Fixes #33575.
2020-08-12 18:40:57 -04:00
Nathan Shively-Sanders d371ae770d
No this-property assignments in TS (#40009)
* No this-property assignments in TS

Even when `this` is aliased, which I mistakenly allowed in #39908.

* remove errant file
2020-08-11 15:46:49 -07:00
Wenlu Wang a80f60c6d6
fix export * as default syntax (#39803)
* fix export * as default syntax

* update comments
2020-08-10 16:56:45 -07:00
Nathan Shively-Sanders 1ec71f0e0c
Bind alias ThisProperty assignment declarations (#39908)
* Bind alias ThisProperty assignment declarations

This is a quick prototype that does the wrong thing at the wrong time
with the wrong technique.

* Preliminary checker handling for aliases

Duplicative and untested, but I think I updated all the places that need
updating.

* new is error; old one should not have been removed

* I don't even know what's happening with this test

* cleanup and testing in the checker

* binder: use lookupSymbolForNameWorker instead of mutable

This should have about the same behaviour and is much easier to
understand.

Also refactor common code a bit.

* Shorter name of lookupSymbolForName

Once upon a time there was a parent/worker function, but now it's just a
single function again. No need for the -Worker suffix.

* remove oodate comment

* fix switch-case-break lint

* Refactor and move functions

* Rename and improve type of getContextualTypeForAssignmentDeclaration
2020-08-10 16:45:55 -07:00
Wesley Wigham 94989789df
In JS declaration emit, move imports painted in nested contexts to the root private context (#39818)
* In JS declaration emit, move imports painted in nested contexts to the root private context

* Add test for nathan
2020-07-31 18:25:37 -07:00
Ron Buckton 32934a9989
Merge pull request #39824 from microsoft/fix35484
Allow assignments to a narrowable reference to be considered narrowable
2020-07-30 15:27:34 -04:00
Andrew Branch 7119e2b74f
The iteration type of overloaded iterator signatures derives from the intersection of their return types (#39722) 2020-07-30 11:37:04 -07:00
Ron Buckton b9db6413bf Allow assignments to a narrowable reference to be considered narrowable 2020-07-29 16:37:25 -07:00
Nathan Shively-Sanders 9b2d487392
Fix this-parameter emit for JSDocFunction types (#39814)
* Fix this parameter emit for JSDocFunction types

Previously, parameters with names that were not `new` were treated like
rest parameters. This is incorrect: parameters with the name `this`
should emit a `this` parameter.

Fixes #38550

* ❤️ quote style
2020-07-29 14:11:59 -07:00
Andrew Branch 1f1521c2f1
Undo accidental change from #39772 (#39779)
* Undo accidental change

* Delete test
2020-07-27 16:55:59 -07:00
Andrew Branch 68ba670467
Add contextual type for generator return type (#39772)
* WIP

* Add contextual type for generator return type
2020-07-27 15:14:47 -07:00
Anders Hejlsberg c5d21e7987
Lower priority for speculative variadic tuple inferences (#39723)
* Inference to [...T, X?] has lower priority than inference to [...T, X]

* Update tests

* Accept new API baselines
2020-07-24 15:00:53 -07:00
Song 8a05707559
Fix 31995: make cached key more precise to avoid returning wrong cached value. (#39670)
* fix 31995

* revert useless change only for debug.

* add test
2020-07-22 12:26:17 -04:00
Anders Hejlsberg db79030410
Support variadic tuple inference from trailing optional to non-optional (#39614)
* Permit variadic tuple inference from trailing optional to non-optional

* Add tests
2020-07-15 17:46:48 -07:00
Andrew Branch dd2fc86f2b
Don’t give all instantiated signatures in JS strict arity (#39606) 2020-07-14 18:56:50 -07:00
Ron Buckton 5ad8532a11 Merge branch 'master' into fix37113
# Conflicts:
#	src/compiler/transformers/module/module.ts
2020-07-13 11:13:35 -07:00
Andrew Branch 583bd92bc4
Don’t create expando declarations on alias symbols (#39558)
* Don’t create expando declarations on alias symbols

* Update other baseline

* Fix brace nesting refactor mistake
2020-07-13 10:05:48 -07:00
Nathan Shively-Sanders 3b107fec3b
Fix @param type parameter lookup (#39532)
Previously, getObjectTypeInstantiation had special-case code to look up
type parameters for `@param` as if they were in the parameter location.

This should occur in the main lookup loop of `getOuterTypeParameters`,
however. The current code only runs once, which is not sufficient, and
it also jumps to the parameter for any type contained in a `@param`,
which skips type parameters that occur in the tag itself.
2020-07-10 08:42:25 -07:00
Wesley Wigham dd2b2447d0
Add regression test for #38834 (#39479) 2020-07-08 13:32:15 -07:00
Nathan Shively-Sanders 53a756ea63
Type this in more constructor functions (#39447)
* Type `this` in more constructor functions

Previously,  `this: this` in constructor functions only when there was
an explicit `@constructor` tag on the function. Now, `this: this` for
any function that's known to be a constructor function.

This improves completions inside constructor functions; also note that
previously the compiler *did* type `this: this` inside methods of constructor
functions, so this fix makes us more consistent. This is reflected in
the large number of baselines that improve.

The fix is a simple switch to `isJSConstructor`, which is the standard
way to detect constructor functions. I'm not sure why the original PR
didn't use this method.

I remember discussing this limitation in the original bug, #25979, and
I guess I decided that it made sense. But I was heavily primed by the bug's
framing of the problem in terms of `noImplicitThis`, which *should*
require an explicit `@constructor` tag.

With better typing comes better detection of `@readonly` assignment; I
had to fix the readonly detection code to use `isJSConstructor` as well.

* Remove `Add @class tag` fix for noImplicitThis.

The new rules mean that it never applies. It's possible that it should
apply to functions like

```js
function f() {
  this.init()
}
```

In which `init` is never defined, but I think this program is incomplete
enough that not offering the fix is fine.

* Fix precedence of `@this`

Previously, both `@class` and `@this` in a jsdoc would cause the `@this`
annotation to be ignored. This became a worse problem with this PR,
because `this` is correctly typed even without the annotation.

This commit makes sure that `@this` is checked first and used if
present.
2020-07-08 08:44:17 -07:00
Ron Buckton 5c5f180f8e Fix namespace import/export helper usage 2020-07-07 17:36:59 -07:00
Anders Hejlsberg 8c6b85835f
Properly handle rest parameters in function declarations with @type annotations (#39473)
* Properly handle rest parameters in function declarations with @type annotations

* Add tests
2020-07-07 16:35:37 -07:00
Wesley Wigham d2b32b422f
Ensure type/namespaceish statics are included in the list of namespace merge members (#38920)
* Ensure type/namespaceish statics are included in the list of namespace merge members

* Simplit into two lines

* Update baseline post-merge
2020-07-07 16:28:09 -07:00
Ron Buckton b100680a3e
Fix for relating covered discriminants in unions (#39393) 2020-07-07 13:11:55 -07:00
Nathan Shively-Sanders 9a65658b28
Parse *= separately in types (#39457)
* Parse *= separately in types

Previously, when the scanner produced `*=` as a single token, the type
parser ran special-case code to produce an "optional all type", which
only makes sense when the `=` really should be attached to the `*`. This
is often not the case.

The correct solution, which I missed when I first wrote this code, is to
have the scanner go back and produce a separate `=` token, which is what
this PR does.

* add test from #38551

* we ❤️ semicolons
2020-07-07 08:30:42 -07:00
Nathan Shively-Sanders 0d84f210b7
In JS, assignment to void 0 isn't a declaration (#39452)
Previously, property assignments with `void 0` initialisers were treated
like any other values. But this causes us to choke when checking our own
commonjs emit. This is something that happens by mistake a fair amount,
so this PR goes back to treating these assignments as normal
assignments.

This should allow us to check our own emit in loose cases without
harming other code bases, since `void 0` is rarely written by hand.

Note that other errors still happen: noImplicitAny forbids
accessing undeclared properties on object literals, and strictNullChecks
forbids assigning `undefined` to properties with a different type.
However, this change is enough to unblock compilation with
`strictNullChecks: false`.
2020-07-06 14:00:12 -07:00
Ron Buckton 652a1c5950
Emit fallback for decorator metadata for type only imports (#39337) 2020-07-02 11:39:27 -07:00
Ron Buckton 8eba362a01 Fix for relating covered discriminants in unions 2020-07-02 11:09:14 -07:00
Anders Hejlsberg 784396ce95
Infer implied arity before inferring from 'this' argument (#39328)
* Infer implied arity before inferring from 'this' argument

* Add regression test
2020-06-29 17:38:41 -07:00
Anders Hejlsberg b448540644
No speculative inferences for variadic tuples (#39281)
* No speculative inferences to types like [...T, U?]

* Add tests
2020-06-29 15:24:32 -07:00
Andrew Branch 58ed610ef1
Allow distinct string enum members with identical property names to form unions in mapped types (#39101) 2020-06-29 10:08:17 -07:00
Wenlu Wang 6b4d0bff40
Avoid effect of element access expression (#39174)
* Avoid effect of element access expression

* Avoid unnecessary copy

* Add more tests
2020-06-25 17:38:05 -07:00
Anders Hejlsberg ee4aee0531
Handle 'keyof' for generic tuple types (#39218)
* Handle keyof T where T is generic tuple type

* Add tests

* Accept new baselines

* Address CR feedback

* Accept new baselines
2020-06-25 13:49:20 -07:00
Anders Hejlsberg 8df85b5cae
Disable unsound T[K] rule in subtype relations (#39249)
* Disable unsound T[K] rule in subtype relations

* Add test
2020-06-25 10:22:48 -07:00
Ron Buckton 0b1d4a9c96
Leverage syntax cursor as part of reparse (#39216) 2020-06-23 17:32:58 -07:00
Anders Hejlsberg d4792062bf
Variadic tuple types (#39094)
* Initial implementation of variadic tuple types

* Accept new baselines

* Handle variadic elements in tuple type inference

* Special case inference between tuples with matching structure

* Restore check that rest element is last element

* Handle variadic tuples in relationship checking

* Accept new baselines

* Infer readonly constraints when inferring from readonly tuples

* Fix lint issues

* T assignable to readonly [...T] and [...T] assignable to T

* Consistent tuple normalization

* Create variadic tuple types from array literal expressions

* Accept new baselines

* Array literals have tuple types when contextual type is readonly

* Accept new baselines

* Optional elements before required elements become required elements

* Update logic for rest parameters and spread arguments

* Revert special case of contextual readonly array type

* Accept new baselines

* Fix lint issue

* Switch entirely to createTupleType based on element flags

* Don't infer readonly tuple types when inferring to variadic elements

* Handle mapped types applied to generic tuple types

* Handle constraint of indexed access type with generic tuple type

* Accept new baselines

* Address CR feedback

* Simplify indexed access types involving generic tuple types

* Propagate checkMode into getSpreadArgumentType

* Guard against missing globalArrayType

* Inference to [...T, ...U] based on implied arity of T

* Accept new baselines

* Add tests

* Emit .d.ts from tests

* Address CR feedback
2020-06-22 18:35:43 -07:00
Jack Williams fd0ad2985b
Minor fix for assertion predicates (#38710) 2020-06-20 18:27:51 -07:00
Ron Buckton fe33e61823
Reparse top level 'await' in modules (#39084)
* Reparse top-level 'await' in modules

* Add more tests and additional diagnostics

* One more incremental parse test
2020-06-18 23:43:18 -07:00
Noj Vek f697d26ca1
reset soft with master for single commit (#38720) 2020-06-18 00:22:32 -07:00
Nathan Shively-Sanders c3c6be6618
In JSDoc, parse postfix-? below conditional types/tuple types (#39123)
Outside of JSDoc comments, postfix-? is parsed at lower precedence than
the `?` of conditional types, and a postfix-? inside a tuple type
results in the type being marked optional.

This PR changes JSDoc parsing to behave the same way, which means that

1. Conditional types are allowed in JSDoc. Fixes #37166.
2. Tuple types' postfix-? syntax is interpreted correctly in JSDoc.
Fixes #38747.

The breaking change is that a postfix-? type followed by another postfix type,
like `[]` or `!`, is parsed as a conditional type. [Postfix-? is not
common](https://github.com/microsoft/TypeScript/issues/37166#issuecomment-612274456),
so this is an acceptable breaking change.

A postfix-? type `T?` is still parsed everywhere else and treated as `T | null`.
2020-06-17 14:06:39 -07:00
Wenlu Wang 6c11ceb8db
Assignment operator is definite assignment (#39087)
Co-authored-by: Orta Therox <orta.therox@gmail.com>
2020-06-16 16:44:01 -04:00