Commit Graph

3835 Commits

Author SHA1 Message Date
Anders Hejlsberg
db226a80e8 Remove unnecessary check in getNarrowableTypeForReference (#47953)
* Remove unnecessary check in getNarrowableTypeForReference

* Add regression test
2022-02-18 11:03:48 -08:00
islandryu
b8b1201e44 fix(47024):fix type of DateTimeFormat and NumberFormat (#47117)
* fix type of DateTimeFormat and NumberFormat

* add NumberFormat to esnext.intl.d.ts

* Update src/lib/esnext.intl.d.ts

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>

* better unification of previous changes

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2022-02-17 15:37:43 -08:00
DetachHead
092018bd7e fix issue where duplicate default exports aren't detected (#46871)
* fix issue where duplicate default exports aren't detected when there's an interface

* accept baseline change

* add `exportDefaultInterfaceClassAndValue` test

* add more tests for multiple default exports

* add two interfaces test

Co-authored-by: DetachHead <detachhead@users.noreply.github.com>
2022-02-17 13:17:31 -08:00
Jonas Hübotter
fb1066e5d9 Uncalled function checks only works with single conditional (#42835)
* Uncalled function checks only works with single conditional

* fix type errors in compiler

* remove uncalled function checks with negations

* review

* fix test

* Cleanup after merge, accept baselines

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2022-02-17 11:37:55 -08:00
Anders Hejlsberg
5afbfbcbd0 Instantiation expressions (#47607)
* Permit type arguments in references to generic functions

* Accept new baselines

* Delete pointless fourslash test

* Fix lint issue

* Finalize implementation

* Add tests

* Accept new baselines

* Properly handle instantiation of instantiation expression types

* Accept new API baselines

* Fix lint error

* Add more tests

* Properly handle unions/intersections of generic types

* Add more tests

* More permissive parsing of type arguments in member expressions

* Update tests

* Accept new baselines
2022-02-16 13:27:16 -08:00
Zzzen
81d1457738 mark length of readonly tuple as readonly (#47717) 2022-02-15 15:02:36 -08:00
Jihn Dai
1e60c8702c Fix inference for generic-typed constructor parameter when no explicit constructor is present (#47750)
* assume signature is from constructor if declaration is undefined

* add tests and baselines
2022-02-15 14:21:44 -08:00
Gabriela Araujo Britto
67f47bf420 Fix incorrect rest element type inside contextually typed parameter (#47909)
* wip: possible fixes

* pass parameter type to assignBindingElementTypes

* undo unnecessary changes

* update baselines
2022-02-15 13:27:23 -08:00
Wesley Wigham
e32281cc02 Allow extensionless mains for cjs mode packages even from an esm import (#47893) 2022-02-14 14:13:21 -08:00
Wesley Wigham
1bdb0d90bf ESM mode nonrelative imports should assume index.js entrypoints even if no package main is present (#47854) 2022-02-11 15:44:11 -08:00
Wesley Wigham
e204acfa26 Ensure subtype relation ordering for readonly properties (#47069)
* Ensure subtype relation ordering for readonly properties

* Probably fix post-LKG assignability error
2022-02-11 14:59:01 -08:00
Wesley Wigham
033f9e0081 Consider a symbol visible for declaration emit when it is the target of an ambient module's export= (#47835)
* Consider a symbol visible for declaration emit when it is the target of an ambient module's export=

* Just use resolveExternalModuleSymbol
2022-02-11 14:58:31 -08:00
Andrew Branch
0655f32e05 Add missing isolatedModules error for export import (#47838)
* Add missing isolatedModules error for `export import`

* Update existing baseline
2022-02-10 16:13:04 -08:00
islandryu
95c22d1750 fix(47076):Fix error term of declaration in modules (#47087)
* Fix error term of declaration in modules

* fix test

* change error code of "An import declaration can only be used at the top level of a module."

* Separate js and ts files for export errors in module.

* Change non-top-level error in namespace

* format

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2022-02-09 13:19:30 -08:00
Gabriela Araujo Britto
2d0a00d457 Fix destructuring and narrowing interaction (#47337)
* WIP: pass in checkmode to getNarrowableTypeForReference

* add tests

* another pass through new check mode argument

* rename new check mode

* only use rest flag for rest elements in objects

* add and update tests

* change check mode flag name

* restore package-lock.json

* fix comments

* get rid of fourslash tests

* fix caching in checkExpressionCached when checkMode is not normal

* Don't distinguish between object and array rest elements

* get rid of undefined check mode

* don't make includeOptionality into checkmode flag
2022-02-09 12:25:07 -08:00
Andrew Branch
2cf5afd49e Avoid pulling on setter type when only getter type is needed to break circularity (#47818) 2022-02-09 10:56:29 -08:00
Andrew Branch
c5b1011e94 Compute writeType from set accessors for union and intersection properties (#47674)
* Compute write type from set accessors for union and intersection properties

* Add test for deferred writeType

* Always check for writeType of symbol
2022-02-08 12:57:34 -08:00
Andrew Branch
d8ac54bfb1 Fix substitution types of indexed access types of substitution types (#47791)
* Fix substitution types of indexed access types of substitution types

* Add tests

* Fix accidental unindentation
2022-02-07 15:53:13 -08:00
Ryan Cavanaugh
2172e1964f Correctly check computed property names in type-space get/set accessors (#47156)
* Add test that should fail

* Make it fail

Fixes #47146

* Baselines
2022-02-01 12:49:05 -08:00
Gabriela Araujo Britto
46e7ab4dbf fix typefacts of intersection (#47583) 2022-02-01 12:10:43 -08:00
magic-akari
0f3809eff1 fix: enum self reference (#47287)
* fix: enum self reference

* fix: add test case

* chore: clean code

* fix: check `errorType` directly

* chore: revert refactor of `isConstantMemberAccess`
2022-01-26 14:13:34 -08:00
Gabriela Araujo Britto
3cbc8d2231 Fix narrowing of intersection with function type (#47483)
* add and and or mask to typefacts

* add comment
2022-01-21 12:05:34 -08:00
Armando Aguirre
ab4d3198ed Fixed Go To Definition using jsconfig (#47434)
* Fixed Go To Definition using jsconfig

* Fixed formatting
2022-01-20 14:45:29 -08:00
Wesley Wigham
bae0f50818 Fix import assertion occurrences crash and make import assertion parsing more generous (#47535) 2022-01-20 14:08:47 -08:00
Robert Snow
08221166d9 Add missing currencyDisplay to resolved number format options (#44006)
* Add missing currencyDisplay to resolved number format options

* Move declaration to es2020

* Update es2020.intl.d.ts

* Fix bad merge

Co-authored-by: Orta Therox <ortam@microsoft.com>
Co-authored-by: Orta Therox <git@orta.io>
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2022-01-18 13:54:25 -08:00
Jake Bailey
e2c00331d6 Bind RHS of comma expressions too (#47049) 2022-01-18 11:46:09 -08:00
Pimm "de Chinchilla" Hogeling
cecd8c50a0 Make Map constructor argument optional and nullable (#43396)
* Make Iterable Map constructor argument optional

Fixes #37779

* Change Map constructor in iterable to accept both null and undefined.

According to the spec (https://tc39.es/ecma262/#sec-map-iterable), the sole argument passed to Map is allowed to be null or undefined.

* Changed Map constructor to ensure new Map() still types as Map<any, any>.

* Add map constructor test.

This proves that the previous commit fixes #37779, as well as that new Map() still types as Map<any, any>.

* Update baseline.

Co-authored-by: Jared Neil <jaredneil@lucidchart.com>
2022-01-18 13:39:05 +00:00
Josh Goldberg
b7fee7f1ee Allowed non-this, non-super code before super call in derived classes with property initializers (#29374)
* Allowed non-this, non-super code before super call in derived classes

Fixes #8277.

It feels wrong to put a new `forEachChild` loop in the checker, though in the vast majority of user files this will be a very quick one. Is there a better way to check for a reference to `super` or `this`?

* Used new isNewThisScope utility and dummy prop in baselines

* Accounted for parameters and get/set accessor bodies

* Accounted for class extensions

* (node|statement)RefersToSuperOrThis wasn't checking root level scope boundaries

```ts
function () {
    return this;
}
```

It was immediately going to `ts.forEachChild` so the statement itself wasn't being counted as a new `this` scope.

* Better 'references' name and comments; accounted for more method edge case

* Limited super calls to root-level statements in constructor bodies

As per discussion in the issue, it would be ideal to consider any block that always ends up calling to super() the equivalent of a root-level super() statement. This would be valid:

```ts
foo = 1;
constructor() {
    condition() ? super(1) : super(0);
    this.foo;
}
```

...as it would compile to the equivalent of:
```ts
function () {
    condition() ? super(1) : super(0);
    this.foo = 1;
    this.foo;
}

That change would a bit more intense and I'm very timid, so leaving it out of this PR. In the meantime the requirement is that the super() statement must itself be root-level.

* Fixed error number following 'master' merge

* Added decorator test cases

* Again allowed arrow functions

* Accepted new baselines

* Added allowance for (super())

* Reworked emitter transforms for ES this binding semantics

In trying to adjust to rbuckton's PR feedback, this orders derived class constructor bodies into five sections:

1. Pre-`super()` code
2. The `super()` call itself
3. Class properties with initializers
4. Parameter properties
5. The rest of the constructor

I've looked through the updated baselines and it looks like they're generally better than before. Within the existing test cases that result in semantic errors for `this` access before `super`, several previously resulted in a global `_this` being created; now, they correctly defer referring to `_this` until it's assigned to `_super.call(this) || this`.

* Used skipOuterExpressions when diving for super()s; fix prop ordering

* Allow direct var _this = super() when no pre-super() statements; lint fixes

* Always with the TSLint

* One last touchup: skipOuterExpressions in es2015 transformer

* Fixed new lint complaint in utilities.ts

* Again added a falls-through; it'd be swell if I could run linting locally

* This time I think I got it

* Well at least the error is a different one

* Undid irrelevant whitespace changes

* Mostly addressed private/field issues

* Accepted derivedClassSuperProperties baseline

* Lint fix, lovely

* Remove now-unnecesary comment

* First round of feedback

* Moved prologue statements to start of statements

* Added consideration for super statements in loops and the like

* Ordering and a _this_1 test

* Missed the one change I needed...

* First round of feedback corrections

* Feedback round two: statements

* Feedback: used more direct statements

* Fixed classFields emit to not duplicate temp variables

* Refactored es2015 helper to be less overloaded

* Accounted for parentheses

* Simpler feedback: -1, and emptyArray

* Next feedback: superStatementIndex

* Feedback: simplified to no longer create slice arrays

* Adjusted for default and rest parameters

* Added test case for commas

* Corrected comment ranges

* Handled comments after super, with tests

* Fixed Bad/Late super baselines

* Remove unused param and unnecessary baseline comments

Co-authored-by: Orta Therox <orta.therox@gmail.com>
Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2022-01-13 20:29:37 -08:00
Anders Hejlsberg
4d6dd119d5 Add missing mapped type indexed access constraint (#47370)
* Type { [P in K]: E }[X] has constraint E with X substutited for P

* Add regression test

* Fix PragmaMap and ReadonlyPragmaMap declarations

* Explore additional constraint

* Revert previous change

* Add tests
2022-01-11 07:23:18 -08:00
Andrew Branch
852b1c2b73 Fix checker initialization crash with esModuleInterop and global merges resolving to ImportEquals aliases (#47348)
* Add minimal failing test

* Fix checker initialization crash with esModuleInterop global merges resolving to ImportEquals aliases
2022-01-10 16:04:12 -08:00
Jake Bailey
484f1414d6 Prevent merged class/namespace from overlapping with Record<string, unknown> (#47088) 2022-01-07 11:02:48 -08:00
Kagami Sascha Rosylight
363e3a78f4 Add Error.prototype.cause (#47020)
* Add `Error.prototype.cause`

Fixes #47019

* Update test baselines
2022-01-07 14:58:58 +00:00
Zzzen
a42379179b fix merging of function and derived class (#47170) 2021-12-16 17:29:07 -08:00
Oleksandr T
c282771d59 fix(47004): ignore arguments name in PropertyAssignment (#47054) 2021-12-16 13:05:48 -08:00
Anders Hejlsberg
3d3825e783 Fix multiple issues with indexed access types applied to mapped types (#47109)
* Fix multiple issues with indexed access types applied to mapped types

* Add tests
2021-12-14 11:51:03 -08:00
Armando Aguirre
67872a50d0 Fix enums and namespace merge (#47059)
* Fix enums and namespace merge

* Remove unused comment
2021-12-13 14:03:19 -08:00
Oleksandr T
df87a8c12d fix(44693): emit declaration of JSDoc overridden properties with different types (#46797) 2021-12-10 11:06:59 -08:00
Jake Bailey
0ed9247e17 Explicitly Omit unspreadable properties from rest type in the generic case (#47078) 2021-12-09 11:45:52 -08:00
Ron Buckton
67f84ef771 Fix Awaited<T> for onfulfilled callbacks with more than one argument (#46951) 2021-12-07 15:21:11 -08:00
Ryan Bargholz
7a12909ae3 fix(45713) Improve error report summaries (#45742)
* Improve error report summaries (#45713)

* fixup! Improve error report summaries (#45713)

* fixup! fixup! Improve error report summaries (#45713)

* Adds support for handling localization renaming the 'files' header due to localization

* fixup! Adds support for handling localization renaming the 'files' header due to localization

 - Fixed baseline error
 - Fixed linter error

Co-authored-by: Orta <git@orta.io>
Co-authored-by: Orta Therox <ortam@microsoft.com>
2021-12-07 10:50:44 +00:00
Zzzen
7a1687de26 fix(42678): detect access to uninitialized variable in IIFE (#42776)
* fix(42678): detect access to uninitialized variable in IIFE

* improve performance

* Add missing space to match coding guidelines

* simplify the implementation

Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
2021-12-06 10:42:20 -08:00
Yuki Osaki
1f275d705d "No repeated property names" error in object literals is duplicated in strict mode (#46929)
* "No repeated property names" error in object literals is duplicated in strict mode

* fix indent
2021-12-06 10:22:28 -08:00
Wesley Wigham
97a7901f26 Use features for selected module resolution rather than all features for type reference directives, since they can add restrictions to resolutions (#47007) 2021-12-04 04:24:28 -08:00
Oleksandr T
c5d9200ec6 feat(46986): offer QF for using await outside of async context (#46994) 2021-12-03 12:36:19 -08:00
Oleksandr T
719ab0b477 fix(43359): emit default exports with named exports that have the same names with types (#44718) 2021-11-12 11:25:52 -08:00
Kagami Sascha Rosylight
ae582a22ee Add target: "es2022" (#46291)
* Add `target: "es2022"`

* Add Object.hasOwn

* formatToParts is es2018

* ref update

* optional parameter

* Revert "optional parameter"

This reverts commit e67d6e5f60.

* undefined

* error cause

* Lint fix

Co-authored-by: Orta <git@orta.io>
2021-11-04 10:55:11 -07:00
Oleksandr T
ff75b8a180 fix(46615): remove useless assertion. change error suggestion for rest params (#46628) 2021-11-03 14:11:39 -07:00
Anders Hejlsberg
33fe1b6ffc Fix contextual typing for symbol-named properties (#46558)
* Properly handle symbol-named properties in contextual types

* Update index signature in PropertyDescriptorMap

* Add regression tests
2021-11-02 14:05:41 -07:00
Anders Hejlsberg
56f81075f9 Properly check whether union type contains only primitive types (#46645)
* Properly check whether union type contains only primitive types

* Add regression test

* Remove 'export' modifier from test
2021-11-02 12:46:26 -07:00
Anders Hejlsberg
7cbcfeea99 Exclude identity relation from mapped type relation check (#46632)
* Exclude identity relation from mapped type relation check

* Add regression test
2021-11-02 06:54:35 -07:00