11774 Commits

Author SHA1 Message Date
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
Isabel Duan
ae9c671d59
(fix #50725, #50710) add file extensions in import statements (#51702)
* fixes #50725

* fixed 50710

* fixed broken test

* clean up

* variable rename

* rename variable to newFileBaseName
2022-12-06 09:28:10 -08:00
Oleksandr T
0eca6b0edc
fix(40365): handle deprecated properties of merged interfaces (#51640) 2022-12-05 15:06:18 -08:00
Wesley Wigham
e9e7a9d49a
Fix #51623 (#51762)
* Fix #51623

* Revert newline changes
2022-12-05 12:48:11 -08:00
Lyu, Wei-Da
0c09d2f172
quick fix for a nullable missing callback function (#51743) 2022-12-05 12:23:59 -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
Gabriela Araujo Britto
6a3c9ea125
Exhaustive case completion for switch statements (#50996)
* fix services' type's isLiteral

* update literal completions tests

* initial prototype

* use symbol to expression. TODO: filter existing, replace import nodes

* WIP

* WIP

* remove booleans from literals

* trigger at case keyword positions

* clean up tests

* fix element access expression case

* refactor dealing with existing values into a tracker

* fix merge errors

* cleanup and more tests

* fix lint errors

* more merge conflict fixes and cleanup

* use appropriate quotes

* small indentation fix

* refactor case clause tracker

* experiment: support tabstops after each case clause

* address small CR comments

* fix completion entry details; add test case

* fix lint errors

* remove space before tab stops; refactor
2022-12-01 16:48:32 -08:00
Eyal Halpern Shalev
5435efbf37
Fixed method signature of Atomics.waitAsync (#51602)
* Added method overloading for Atomics.waitAsync(Int32Array, number, number, number)

* fixed types

* fixed types

* fixed line ending

* CR fix

* Forgot the baseline
2022-12-01 16:41:28 -08:00
Oleksandr T
1b75edcec6
fix(51053): Extract type on JSDoc causes an assertion failure (#51056)
* fix(51053): allow extract type from the jsdoc without a host

* change diagnostic message
2022-12-01 16:09:31 -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
8036b149a4
Fix isUnitLikeType to (again) handle tagged literal types (#51545)
* Fix isUnitLikeType to (again) handle tagged literal types

* Add regression test
2022-11-30 13:30:52 -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
Andrew Branch
e6d7b526c8
Fix multiline import specifier sorting (#51634)
* Fix multiline import specifier sorting

* Update baselines

* Switch to EmitFlag, set hasTrailingComma on original node array

* Update API baseline

* Update baselines
2022-11-28 15:35:32 -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
89ce16ccfd
Fix auto-import when paths points to project reference redirect (#51492)
* Fix auto-import when `paths` points to project reference redirect

* Put paths specifiers to redirects in lower priority bucket
2022-11-15 14:19:15 -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
Oleksandr T
5016d13f8d
fix(51112): skip checking binding parameters for functions that contains arguments (#51258) 2022-11-14 16:32:36 -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
Jake Bailey
36e29448e9 Get codebase building pre bundling
This isn't totally complete, but enough to get everything building and
tests running manually. The next commit will make the build work fully.
2022-11-07 13:34:44 -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
Oleksandr T
fa4b49d541
fix(51374): ts(80004): Quick fix... > Annotate with type from JSDoc :: object types (#51378)
* fix(51374): transform JSDocTypeLiteral

* add additional tests

* add additional tests
2022-11-07 11:35:08 -08:00
Anders Hejlsberg
f0216e3421
Improve reduction of similar intersections in type inference (#51405)
* Change criteria for reducing intersections in type inference

* Add regression test
2022-11-04 17:04:05 -07:00
Anders Hejlsberg
7cf842b42b
Enum unification and improvements (#50528)
* Fix enum classification and evaluation

* References in literal enums must be to other enum members

* Accept new baselines

* Unify enum types + template literal constant expressions

* Accept new baselines

* Fix fourslash tests

* Fix new compiler errors

* Fix lint error

* Accept new API baselines

* Fix test

* Better error message + consistently check enum initializers

* Accept new baselines
2022-11-03 11:05:42 -07:00
Zzzen
6017625ad5
do not report use-before-declaration error in async IIFE initializer (#50199) 2022-11-02 11:41:04 -07:00
Mateusz Burzyński
46b015f2bf
Fixed the issue with some longer variadic tuples with any rest being incorrectly assignable to shorter variadic tuples (#50218) 2022-11-02 11:35:17 -07:00
Gabriela Araujo Britto
fdcb2ffd1b
Fix services' type's isLiteral implementation (#50929)
* fix services' type's isLiteral

* update literal completions tests

* remove booleans from literals
2022-11-02 11:28:10 -07:00
Wesley Wigham
4d15bb16e1
Fix #50869, only cache calculated type for non-context sensitive parameters (#50976)
* Fix #50869, only cache calculated type for non-context sensitive parameters

* Simplify check, update comment
2022-10-31 17:24:51 -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
Oleksandr T
64d0d5ae14
fix(51301): Fixing an unused import at the end of a line removes the newline (#51320)
* fix(51301): keep the line break after removing the unused identifier

* preserve line breaks in import specifiers

* preserve line breaks in parameters and destructuring elements

* remove preserveLineBreak option
2022-10-27 17:27:36 -07:00
Oleksandr T
d4f26c840b
fix(51245): Class with parameter decorator in arrow function causes "convert to default export" refactoring failure (#51256)
* fix(51245): don't rely on parent nodes in formatting rules

* check existing parent node
2022-10-26 16:59:44 -04:00
Oleksandr T
8b1ecdb701
fix(50654): "Move to a new file" breaks the declaration of referenced variable (#50681)
* fix(50654): remove entire import require call instead of the name

* handle require imports in ts files
2022-10-25 17:05:57 -07:00
Oleksandr T
88d25b4f23
fix(50068): Refactors trigger debug failure when JSX text has a ' and a tag on the same line. (#51299)
* fix(50068): rescan JsxText on JsxElement context

* fix lint errors

* add tests
2022-10-25 13:10:31 -07:00
Andrew Branch
ef69116c41
Generate shortest rootDirs module specifier instead of first possible (#51244)
* Generate shortest rootDirs module specifier instead of first possible

* Simplify `min`
2022-10-21 16:05:58 -07:00
Ron Buckton
a56b254ad3
Include 'this' type parameter in isRelatedTo fast path (#51230) 2022-10-21 08:00:24 -04:00
Ron Buckton
3abd351c0e
Fix super property transform in async arrow in method (#51240) 2022-10-21 08:00:00 -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
Anders Hejlsberg
906ebe4933
Revert structuredTypeRelatedTo change and fix isUnitLikeType (#51076)
* Revert structuredTypeRelatedTo change, fix isUnitLikeType

* Accept new baselines

* Add regression tests

* Fix formatting in test
2022-10-19 15:46:00 -07:00
Oleksandr T
245a02cbed
fix(51222): Go-to-definition on return statements should jump to the containing function declaration (#51227)
* fix(51222): add go-to-definition return statement to containing function

* add additional tests
2022-10-19 11:32:39 -07:00
Ron Buckton
2dff34e8c4
markAliasReferenced should include ExportValue as well (#51219) 2022-10-19 13:24:01 -04:00
Mateusz Burzyński
85d405a1d7
Fixed a false positive "await has no effect on the type" diagnostic with mixed generic union (#50833) 2022-10-18 14:10:03 -07: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
Oleksandr T
f25bcb7c27
fix(49196): add jsdoc snippet for interface member functions (#51135) 2022-10-17 17:35:08 -07:00
Oleksandr T
7406ee9c14
fix(51170): Completing an unimplemented property overwrites rest of line (#51175)
* fix(51170): skip insertText for class members with existing initializer

* skip insertText for class members with existing tokens
2022-10-17 13:14:23 -07:00
Andrew Branch
f6cf51053e
Add more tracing to node16/nodenext resolution (#51168)
* Add more tracing to node16/nodenext resolution

* Update baselines after diagnostic change

* Trace non-matching conditions
2022-10-14 09:42:06 -07:00