4026 Commits

Author SHA1 Message Date
Sheetal Nandi
3172629f21 Add new option to cacheResolution (No actual functionality yet) 2022-12-09 14:49:18 -08:00
Josh Goldberg
f3d55db45a
Fixed tuple types indexed by a type parameter (#51037)
* Fixed tuple types indexed by a type parameter

* If only there was a tool to add that missing semicolon for me

* Rename to baseConstraint

Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
2022-12-09 07:59:40 -08:00
Anders Hejlsberg
b9d0e17298
Ignore switch statement bypass control flows that produce never (#51703)
* Ignore switch statement bypass control flows that produce 'never'

* Add regression test
2022-12-07 16:19:09 -08:00
Anders Hejlsberg
d43112a75b
Use missingType in --noUncheckedIndexedAccess mode (#51653)
* Use missingType in noUncheckedIndexedAccess mode

* Accept new baselines

* Add tests

* Optimizing searching for undefinedType and missingType
2022-12-07 13:38:33 -08:00
Anders Hejlsberg
91f89b94e4
Visit child nodes in checkExpressionWithTypeArguments (#51804)
* Visit child nodes in checkExpressionWithTypeArguments

* Accept new baselines

* Add tests
2022-12-07 10:06:12 -08:00
Mateusz Burzyński
6684e3d527
Fixed substition types for non-generic indexed accesses (#51621) 2022-12-07 07:47:32 -08:00
Eric Ferreira
af1d91d9d9
Fix missed errors in switch when using union of literal and non-literal types (#38686) (#51373)
* Fix missed errors in switch when using union of literal and non-literal types (#38686)

This commit makes it so we don’t use the base type of literals when checking comparability in switch. The comparability checks handle that case already, is my understanding, so we don’t need to clobber the type before actually doing the check, causing missed errors.

When comparing the types in switch, if a union with a literal and a non-literal was used, the compiler in `checker.ts` would automatically get the base type of all parts of the union, resulting in missed errors. For example, if the union of the non-literal `number` and literal `"hello"` was compared to the literal `"world"` in a switch case, the compiler would miss that they’re actually not comparable.

Maybe someone can tell me why we were getting the base type before checking comparability, rather than relying on the logic within the comparability checks to handle literal/base type comparability?

* Fix lint (whitespace) issue in checker.ts by running lint with fix flag.
2022-12-06 10:50:21 -08:00
Wesley Wigham
e9e7a9d49a
Fix #51623 (#51762)
* Fix #51623

* Revert newline changes
2022-12-05 12:48:11 -08:00
Anders Hejlsberg
c07f51242c
Fix narrowing by typeof applied to discriminant property (#51720)
* Fix narrowing by typeof applied to discriminant property

* Include effects of getReferenceCandidate

* Add tests
2022-12-05 11:51:54 -08:00
Ryan Cavanaugh
9089d5390a
Unconditionally call checkExpression from checkSatisfiesExpression (#51704)
* Unconditionally call `checkExpression` in `checkSatisfiesExpression`

* A testcase
2022-12-01 09:11:37 -08:00
Anders Hejlsberg
cee6366c48
Fix isTypeDerivedFrom to properly handle {} and intersections (#51631)
* Fix isTypeDerivedFrom to properly handle {} and intersections

* Add tests
2022-11-29 08:29:35 -08:00
Mateusz Burzyński
5cd2d975c3
Fixed an issue with in not being able to be used on narrowed down expression of a generic nullable type (#51502)
* Fixed an issue with `in` not being able to be used on narrowed down expression of a generic nullable type

* Add another test case from a new issue

* Move the fix to `hasEmptyObjectIntersection`
2022-11-22 07:03:58 +01:00
Wesley Wigham
b4024a5506
Preserve input key style when writing mapped type keys in declaration emit (#50781) 2022-11-18 12:54:12 -08:00
Wesley Wigham
a3092c798a
Preserve alias symbols on references to type aliases via imports (#51152)
* Preserve alias symbols on references to type aliases via imports

* Fix lint
2022-11-17 21:25:31 -08:00
Andrew Branch
3fcd1b51a1
Refactor module resolution Extensions, fix lookup priorities (#51471)
* Refactor `Extensions`, fix lookup priorities

* Update baselines

* Clean up

* Temporarily apply same fix to `node` for testing

* Revert ancestor node_modules lookups back to two passes

* Revert "Temporarily apply same fix to `node` for testing"

This reverts commit 4014f3005a2a01a5c71a88e6418cc635498a83bc.

* Update baselines

* Add new test for node_modules searching behavior

* Update new baseline
2022-11-15 14:18:11 -08:00
Jonathan Kingston
c0f8d1cf75
fix(51277): Array find thisArg fix from being void (#51278) 2022-11-14 16:49:11 -08:00
Jake Bailey
9f64a3a58c
Remove ts.{Map,Set,ESMap,Iterator} and associated types (#51439) 2022-11-09 15:06:31 -08:00
Mateusz Burzyński
39ccac654c
Add known keys of the mapped type constraint to its members (#50081)
* Add known keys of the mapped type constraint to its members

* Avoid second pass of adding known members by instead passing `noReductions` to `mapType`
2022-11-07 16:22:27 -08:00
Jake Bailey
c65142244c Add dts bundling
This adds a "small" d.ts bundler script. This script is very basic,
using Node printing to produce its output. Generally speaking, this is
inadvisable as it completely disregards name shadowing, globals, etc.
However, in our case, we don't care about the globals, and we can opt to
restructure our codebase in order to avoid conflict, which we largely
had to do anyway when we were namespaces and everything was in scope.
2022-11-07 13:35:48 -08:00
Mateusz Burzyński
a329210166
Fixed a regression with discriminating unions based on a union property against undefined with strictNullChecks: false (#49648)
* Fixed a regression with discriminating unions based on a union property against `undefined` with `strictNullChecks: false`

* Add additional test case from the issue comment
2022-11-07 12:17:59 -08:00
Zzzen
6017625ad5
do not report use-before-declaration error in async IIFE initializer (#50199) 2022-11-02 11:41:04 -07:00
Ron Buckton
7f8426f4df
fix for-in enumeration containing yield in generator (#51295) 2022-10-28 15:09:10 -04:00
Jake Bailey
3d2b4017eb
Fix assertion functions accessed via wildcard imports (#51324)
* Add test

* Resolve alias of property in getTypeOfDottedName

* Always resolve

* Update tests
2022-10-27 20:27:53 -07:00
Ron Buckton
a56b254ad3
Include 'this' type parameter in isRelatedTo fast path (#51230) 2022-10-21 08:00:24 -04:00
Oleksandr T
1ca99b3402
fix(50551): Destructuring assignment with var bypasses "variable is used before being assigned" check (2454) (#50560)
* fix(50551): handle destructuring variables used before assignment

* skip the error in binding elements that refer to the same destructuring

* fix binding element type
2022-10-20 10:57:43 -07:00
Ron Buckton
2dff34e8c4
markAliasReferenced should include ExportValue as well (#51219) 2022-10-19 13:24:01 -04:00
Joshua Chen
1f8959f5dc
fix: avoid downleveled dynamic import closing over specifier expression (#49663)
* fix: evaluate dynamic import specifier expressions synchronously

* refactor

* Update src/compiler/transformers/module/module.ts

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>

* [Experiment]

Co-authored-by: Ron Buckton <ron.buckton@microsoft.com>
2022-10-18 16:46:51 -04:00
Mateusz Burzyński
be5f0fe5ac
Add an extra regression test for awaited unresolvable recursive union (#51167) 2022-10-13 18:30:35 -07:00
Wesley Wigham
bdcc240d68
Remove bug-causing carve-out in conditional type instantiation that hopefully is no longer required (#51151) 2022-10-13 10:58:42 -07:00
Anders Hejlsberg
37317a208f
Check nested weak types in intersections on target side of relation (#51140)
* Check nested weak types in intersections on target side of relation

* Add regression tests

* Move logic from isRelatedTo to structuredTypeRelatedTo

* Fix lint error

* Add additional test
2022-10-13 08:20:07 -07:00
Anders Hejlsberg
4f54e7e947
Fix isExhaustiveSwitchStatement to better handle circularities (#51095)
* Fix isExhaustiveSwitchStatement to better handle circularities

* Add regression test
2022-10-12 07:22:06 -07:00
Anders Hejlsberg
d06a592d02
Properly defer resolution of mapped types with generic as clauses (#51050)
* Fix isGenericMappedType, getTemplateLiteralType, getStringMappingType

* Accept new baselines

* Add regression tests

* Fix comment
2022-10-07 07:25:57 -07:00
Jake Bailey
8af9a936b5
Use typescript.d.ts in APISample tests (#51061) 2022-10-04 15:00:35 -07:00
Anders Hejlsberg
96894db6cb
Include type parameter defaults in contextual typing (#50994)
* Include type parameter defaults in contextual typing

* Add tests

* Add additional an test for instantiating contextual signature using default type param (#51002)

* Update comment

Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
2022-09-30 07:02:22 -07:00
Daniel Rosenwasser
0d0a793714
Allow Unicode extended escapes in ES5 and earlier (#50918)
* Remove language version check for extended escapes.

* Accepted baselines.

* Record whether nodes have extended Unicode escapes. Replace them in the es2015 transform.

* Accepted baselines.

* Move file to better-reflect generality of tests.

* Added tests for variables at the top level.

* Accepted baselines.

* Added test for extended astral character.

* Accepted baseline.

* Enable sourcemaps in tests.

* Accepted baselines.

* Call `setOriginalNode` on identifiers with extended escapes.
2022-09-30 01:22:01 -07:00
Anders Hejlsberg
ecf50e81a7
Properly compute SymbolFlags.Optional for intersected properties (#50958)
* `in` proves property presence only if property can't be undefined

* Accept new baselines

* Add tests

* Accept new baselines

* Properly compute SymbolFlags.Optional for intersected properties

* Accept new baselines

* Check optionality only for property-like declarations

* Add more tests
2022-09-29 15:18:21 -07:00
Andrew Branch
fbfe9340a9
Fix comparability between type parameters related by a union constraint (#50978) 2022-09-28 10:06:13 -07:00
Oleksandr T
c81bf4d8b0
fix(49594): Typescript 4.7.3 bracketed class property compilation error strictPropertyInitialization:true (#49619)
* fix(49594): allow enum members in computed properties

* add additional tests

* handle enum members without initializers

* update tests
2022-09-26 09:50:02 -07:00
navya9singh
bc9cbbef42
Merge pull request #49912 from microsoft/fix/47508
fix(47508): noUncheckedIndexedAccess with enums Type narrowed
2022-09-26 09:47:33 -07:00
Oleksandr T
2644f28677
fix(49200): skip duplicated method declarations (#50609) 2022-09-21 16:05:40 -07:00
Anders Hejlsberg
01054e05ab
Consistently add undefined/missing to optional tuple element types (#50831)
* Consistently add undefined/missing type to optional tuple elements

* Accept new baselines

* Add regression test
2022-09-20 18:14:20 -07:00
Oleksandr T
e002159ad1
feat(49962): Disallow comparison against NaN (#50626)
* feat(49962): disallow comparison against NaN

* change diagnostic message

* use global NaN symbol for NaN equality comparisons
2022-09-20 13:16:44 -07:00
Oleksandr T
23746af766
fix(50591): RangeError: Maximum call stack size exceeded (#50594) 2022-09-20 11:03:18 -07:00
Andrew Branch
168186f93d
Allow a union property of a private/protected member and an intersection property including that same member (#50328) 2022-09-20 10:28:48 -07:00
Anders Hejlsberg
a11c41621b
Improve checking of in operator (#50666)
* Improve checking of `in` operator

* Accept new baselines

* Add tests

* Delete old and accept new baselines

* Disallow right operand of type '{}'

* Accept new baselines

* Support number and symbol literals

* Add tests

* Disallow {} typed right operand only in strictNullChecks mode

* Accept new baselines

* Detect {} resulting from intersections

* Accept new baselines

* Don't attempt to reduce intersections with Record<K, unknown>

* Accept new baselines

* Return undefined instead of unknownSymbol from getGlobalRecordSymbol()
2022-09-19 14:16:01 -07:00
Gabriela Araujo Britto
3014dec887
Don't elide imports when transforming JS files (#50404)
* don't elide imports in JS files

* WIP: get rid of caching of resolved symbol, add transform tests

* get rid of caching only for resolver functions

* use getReferencedSymbol instead of getReferencedValueSymbol in module transform

* WIP: add reportErrors flag to resolveName

* Import transformations now work correctly

* don't emit diagnostics when looking up referenced symbol

* small fixes and get rid of unnecessary comments

* update tests

* clean up

* CR: use nameNotFoundMessage to decide whether to report errors in resolveName
2022-09-19 11:36:08 -07:00
Gabriela Araujo Britto
48a8e8953a
Improve check of whether type query node possibly contains reference to type parameter (#50070)
* WIP

* implement typequery contains reference check + tests

* add unit test

* fix unit test

* use symbols in scope to check type query type parameter references

* remove comment on unit test

* remove comment

* use isNodeDescendantOf implementation to check scoping

* CR: small fixes

* treat the different kinds of type parameter declarations

* undo test change
2022-09-18 21:13:30 -07:00
Daniel Rosenwasser
0df46e8733
Fix test around RegExp match vs. exec results (#50813)
* Fix up test.

* Accepted baselines.
2022-09-16 16:47:33 -07:00
DetachHead
2970c5d167
make RegExpExecArray always include index 0 (#50713)
* make `RegExpExecArray` always include index 0

* update baseline

* remove `BaseRegExpArray` interface

* add test

Co-authored-by: DetachHead <detachhead@users.noreply.github.com>
2022-09-16 15:28:26 -07:00
Anders Hejlsberg
3b84f76fb2
Fix crash caused by incorrect bounds check (regression in 4.8) (#50797)
* Fix bounds check

* Add regression test
2022-09-16 07:14:14 -07:00