Commit Graph

3859 Commits

Author SHA1 Message Date
Oleksandr T
4a58fbce17 fix(48081): omit error on importing variables defined with require() (#48115) 2022-03-14 09:55:12 -07:00
Mateusz Burzyński
ca65a1a05b Add boolean to supported literals within Object.freeze (#48117) 2022-03-14 09:07:31 -07:00
Wesley Wigham
d1fa945261 Add moduleDetection compiler flag to allow for changing how modules are parsed (#47495)
* Add moduleDetection compiler flag to allow for changing how modules are parsed

The default setting is 'auto', where JSX containing files under react-jsx and react-jsxdev are
always parsed as modules, and esm-format files under module: node12+ are always parsed as modules,
in addition to the 'legacy' detection mode's conditions for other files. (Declaration files are exempt from
these new conditions)

The 'legacy' mode preserves TS's behavior prior to the introduction of this flag - a file is
parsed as a module if it contains an import, export, or import.meta expression.

In addition, there is a 'force' mode that forces all non-declaration files to be parsed as modules.
(Declaration files are still only modules if they contain a top-level import or export.)

This technically breaks the parser API, but it's kinda-sorta backwards compatible so long
as you don't need the functionality associated with more recent compiler flags.

* Fix post-merge lint

* Rename function

* Update default value documentation

* PR feedback

* Fix lint and typo
2022-03-11 10:36:00 -08:00
Anders Hejlsberg
0271738047 Properly reduce intersections to never in identity relation (#48111)
* Exclude types that may simplify to other forms

* Add regression test
2022-03-11 10:18:04 -08:00
Wesley Wigham
3f63804878 Make direct assignments to cjs exports considered literal contexts (#39816)
* Make direct assignments to cjs exports considered literal contexts

* Style feedback from PR

* Trailing whitespaaaaace
2022-03-09 13:27:39 -08:00
Wesley Wigham
f76452cb27 Fix conditional type type parameter leak (#31455)
* Fix conditional type type parameter leak

* Monkey with comment text per code review

* Conditionally clone type param

* Reuse input array and avoid making mapper where possible
2022-03-09 13:25:14 -08:00
Wesley Wigham
fc82c67357 Don't eagerly simplify reducible generic union index types (#46812) 2022-03-09 12:02:11 -08:00
Wesley Wigham
ea4791d4d7 Preserve the homomorphism of inlined mapped types in declaration emit (#48091) 2022-03-09 10:31:54 -08:00
Ryan Cavanaugh
af027f34fa Bail on 0- and 1-length lists in removeSubtypes to avoid spurious circularity problems (#46981)
* Creates a reasonable workaround for #46939

* Remove unrelated newline

* Do the cheap length check ahead of the cache check

* Actually do it.
2022-03-08 08:50:07 -08:00
jihndai
5f6ebf9d78 Show error when trying to instantiate a union of abstract and concrete constructors (#48114)
* check composite signatures for abstract flag

* add tests and baselines

* refactor someSignature into a single function
2022-03-04 17:39:05 -08:00
jihndai
857889a4e6 Fix crash when this is typed as a generic T with no type constraints (#47991)
* fix this type validations for protected fields

* update previous baselines

* add new tests and baselines

* ClassOrInterface can be returned as enclosingClass

* inline function code and remove unnecessary blank lines

* refactor enclosingClass checks
2022-03-04 17:08:44 -08:00
Oleksandr T
82fc9b19ba fix(43154): emit typeof type for static methods with a computed name (#46923) 2022-03-04 17:07:38 -08:00
Oleksandr T
162713fac9 fix(40617): handle uninitialized class member with computed key (#45974) 2022-03-04 16:03:36 -08:00
Zzzen
f9ae305dda support generic type when checking implicit conversion of symbol to string (#44578)
Co-authored-by: Wesley Wigham <wewigham@microsoft.com>
2022-03-04 15:57:34 -08:00
Erik Brinkman
751c114126 Fix contextual discrimination for omitted members (#43937)
In short, the fix I submitted looked at the union ofproperties, but it
really should have looked at the intersection.

Two sytlistic notes. I couldn't find the best way to get the unique
strings of an array like `[...new Set()]` would, so I created a small
helper function, but didn't put it in a great place. Also, before the
second concatenated array of discriminators at least matched the first
in complexity, but now it's much worse. I don't think that section is
particularly easy to read, but I also don't see a significantly reusable
part.

fixes #41759
2022-03-04 14:07:37 -08:00
liewrichmond
ae62da9413 Fixes #35735: Avoids listing missing properties for types with only call/construct signatures (#40973)
* Fixes #35735

* fixes #35735

* PR feedback

Co-authored-by: Wesley Wigham <wewigham@microsoft.com>
2022-03-04 13:54:38 -08:00
Jake Bailey
112dd24ede Add test for call (#48015) 2022-03-03 09:40:10 -08:00
magic-akari
06d426c966 Fix const enum comments (#47990)
* chore: add test case

* fix: const enum comment

* fix: replace all unsafe pattern

* chore: run regex only if element access
2022-03-03 09:10:02 -08:00
Wesley Wigham
ff1f7b15b7 Esm imports of cjs files should unconditionally have a default patched on (#48062) 2022-03-02 08:53:31 -08:00
Oleksandr T
063714886e fix(47946): check literal types in export assignments with declared JSDoc types (#47951) 2022-03-01 14:44:36 -08:00
Wesley Wigham
71918750f9 Use full isReadonlySymbol check rather than declaration flags (#48064)
* Use full `isReadonlySymbol` check rather than declaration flags

* Limit subtype readonly consistency check to strict subtype relation

* Update comment
2022-02-28 14:35:33 -08:00
Wesley Wigham
03c11c8f70 Add missing getReducedType call in getConditionalTypeInstantiation (#48061) 2022-02-28 13:41:10 -08:00
islandryu
ff3b458714 fix(47158): Removes comments when line variable declaration (#47407)
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
2022-02-23 09:33:41 -08:00
Gabriela Araujo Britto
78818e0390 early return if pattern type is never (#47927) 2022-02-22 17:34:02 -08:00
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