Commit graph

157 commits

Author SHA1 Message Date
Clay Miller d934401265 Change the type of 'uriComponent' (passed to 'encodeURIComponent') from 'string' to 'string | number | boolean'. Fixes #18159 (#31103)
- According to the ECMAScript 5.1 spec (§15.1.3.4), 'encodeURIComponent' invokes the abstract operation 'ToString': https://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4
- In the spec (§9.8), 'ToString' accepts an 'Undefined', 'Null', 'Boolean', 'Number', 'String' or 'Object' argument: https://www.ecma-international.org/ecma-262/5.1/#sec-9.8
- TypeScript’s 'StringConstructor' accepts an argument with type 'any': b0100100a1/lib/lib.es5.d.ts (L518)
2019-04-26 13:07:14 -07:00
Daniel Rosenwasser 57938e6cc2 Make Omit alias its own mapped type so that references to it never expand to Pick<...>. 2019-04-24 16:57:20 -07:00
Jordan Harband d4ff58d53f [fix] ES5 Object.keys only accepts an object (#27089) 2019-04-24 10:18:31 -07:00
Daniel Rosenwasser 13d2b8d617 Add the Omit helper type. 2019-04-04 10:01:34 -07:00
Nathan Shively-Sanders 32054f1c31
Forbid accessing block-scoped variables on globalThis (#30510)
* Forbid accessing const & let on globalThis

It's just an error; you still get the type of the property.

* Disallow access of blockscoped vars on globalThis

Also change Array, Function, String, et al from `const` to `var` so that
they remain accessible via `globalThis.String`.

* Update baselines after lib.d.ts change

Note especially the change in redefineArray, which is now allowed as
long as you provide a type that is assignable to ArrayConstructor.

* Remove blockscoped vars from typeof globalThis

Unlike forbidding them, this removes the properties entirely.

Unfortunately, this means that accessing these properties is only an
error with noImplicitAny, and that error is quite confusing.

Let's discuss our options. I see 3:

1. Forbid access of block-scoped vars as properties (in all flag
settings), but leave them on the type. Simple to implement.
2. Remove block-scoped vars from the globalThis type. Has the bad
error/flag behaviour described above, but simple to implement.
3. Remove block-scoped vars from the globalThis type. Also, forbid
accessing them by executing another resolveName lookup for failed
property accesses on globalThisSymbol. If the second lookup returns a
blockscoped var, issue an error instead of falling back to the index
signature. This seems too complex to me.

* Update baselines

* Better error for block-scoped usage on globalThis

So that value-space references have as clear an error as type-space
references.

* Update fourslash tests

* Fix semi-colon lint

* Don't copy so much when filtering blockscoped vars
2019-03-25 14:07:48 -07:00
Ryan Cavanaugh 4ff71ecb98
Merge pull request #29696 from Microsoft/filter-unknown
Use unknown for array predicates' return types
2019-02-04 13:26:29 -08:00
Anders Hejlsberg f86b635122
Merge pull request #29705 from Microsoft/fixParametersAndReturnType
Less restrictive Parameters<T> and ReturnType<T>
2019-02-04 12:08:29 -08:00
Ryan Cavanaugh 0a041ee536
Merge pull request #28270 from AnyhowStep/json-parse-reviver-stringify-replacer-better-declaration
JSON.parse(), JSON.stringify() more specific declarations for #6955
2019-02-02 12:10:56 -08:00
Anders Hejlsberg e7ad76ddc8 Less restrictive constraints in Parameters and ReturnType types 2019-02-02 09:28:21 -08:00
Ryan Cavanaugh efbe630a13
Use unknown for array predicates' return types 2019-02-01 17:05:04 -08:00
Ryan Cavanaugh d85c4e551e
Merge pull request #27121 from xl1/26977-typedarray
Allow non-number source for TypedArray.from
2019-01-24 13:42:43 -08:00
Anders Hejlsberg 9cc997fca7 Improve typing of 'bind' method on function types 2018-12-08 11:02:19 -08:00
AnyhowStep dd3ed02868 Removed stray whitespace 2018-11-13 12:24:03 -05:00
AnyhowStep 01e71820fc Fixes Microsoft/TypeScript#6955 2018-10-31 17:00:24 -04:00
Basarat Ali Syed c86b9ca660
📝 Better description of Pick mapped type
closes https://github.com/Microsoft/TypeScript/issues/25976
2018-10-03 10:57:43 +10:00
xl1 9819b6b7aa Allow non-number array for source of TypedArray.from 2018-09-15 23:00:01 +09:00
Anders Hejlsberg df1e33a8a5 Add 'bind' overloads for rest parameter arrays 2018-09-12 13:17:11 -07:00
Anders Hejlsberg a5dece30d9 Update declarations 2018-09-11 06:14:41 -07:00
Anders Hejlsberg 55b6513078 New CallableFunction and NewableFunction types in es5.d.ts 2018-09-10 15:12:42 -07:00
Nathan Shively-Sanders c929e74310
Add [Constructor]Parameter types to lib.d.ts (#26243) 2018-08-31 07:46:16 -07:00
Daniel Rosenwasser b8ca925de0 Place 'pop' first in 'Array'. 2018-07-10 19:34:19 -07:00
Wesley Wigham 616e6e6ca3
Move symbol instance type to es5 to follow PropertyKey (#23864)
* Move symbol instance type to es5

* Accept baseline changes from moving Symbol
2018-05-03 10:50:10 -07:00
Daniel Rosenwasser 9672116d8c Merge remote-tracking branch 'origin/master' into importDotMeta 2018-04-25 22:21:56 -07:00
Daniel Rosenwasser a55febda77 Make 'ImportMeta' more minimal. 2018-04-24 12:38:42 -07:00
Anders Hejlsberg 16cd5580a6 Merge branch 'master' into improveIndexTypes
# Conflicts:
#	src/compiler/checker.ts
#	src/server/utilities.ts
2018-04-16 16:18:29 -07:00
Daniel Rosenwasser f0081f0a04 Basic checking for 'import.meta'. 2018-04-10 12:59:03 -07:00
Anders Hejlsberg 68ce69a351 Move 'PropertyKey' from es2015.core.d.ts to es5.d.ts 2018-04-09 07:45:55 -10:00
Holger Jeromin c3d8ec0ee2
refactor: use union type in DateConstructor 2018-04-06 11:27:20 +02:00
Priyantha Lankapura 80464e8ff1 fix typo in intellisense (#21914) 2018-02-13 18:52:33 -08:00
Anders Hejlsberg 2cc1d735ec Add Required<T> to lib.d.ts 2018-02-13 06:47:52 -08:00
Anders Hejlsberg 2aba29fc32 Add Exclude, Extract, NonNullable, ReturnType, and InstanceType types 2018-02-09 14:22:46 -08:00
Nathan Shively-Sanders be0fcd5174
Array.concat now takes ConcatArray, not ReadonlyArray (#21462)
* Overloads in Array.concat now handle ReadonlyArray

Previously it was union types, which is slower.

* Make arrayConcat3 test stricter

* Switch to InputArray instead of adding overloads

* Update baselines

* Update baselines correctly

* Rename to ConcatArray and add slice method

Should make it, respectively, easier to understand this specific type
and harder to satisfy it by mistake.
2018-02-02 13:20:40 -08:00
Ryan Cavanaugh 100262537a Remove TODO 2017-12-13 10:58:04 -08:00
Daniel Rosenwasser 53657069bc
Merge pull request #20517 from gagoman/16900
fix docs for Math.ceil and Math.floor (#16900)
2017-12-07 16:56:27 -08:00
Andy 5e5b7706e5
Hack to allow concat to work even when an Array isn't assignable to ReadonlyArray (#20455) 2017-12-07 12:15:12 -08:00
Alex Khomchenko d383f18d72 fix docs for Math.ceil and Math.floor (#16900) 2017-12-06 22:53:42 +01:00
Wilson Hobbs c2f0c580db add types for escape and unescape methods #18813 (#19015)
* add types for escape and unescape methods #18813
although the issue is marked working as expected, it is important to mention that most major browsers maintain support for escape and unescape, and some javascript codebases moving to typescript may have escape and unescape in them. They are valid JavaScript, and thus they should be included in the global definition.

* add escape and unescape types to lib in tests

* update tests to turn CI green
2017-11-13 10:37:54 -08:00
falsandtru d23e5f1ee2 Fix Array.{reduce,reduceRight} methods (#18987) 2017-10-09 17:11:31 -07:00
Adrian Leonhard 8c2d79caa6 TypedArrays: fixed find and findIndex callback param obj type. (#18493)
Fixes #18425.
2017-09-18 12:12:08 -07:00
Thomas den Hollander 1ee3b65141 Change typed array signatures (#18367) 2017-09-11 11:22:45 -07:00
Alex Chugaev de313ff1bd Object.getOwnPropertyDescriptor() returns 'undefined' if property descriptor not found. (#18148) 2017-09-07 10:58:05 -07:00
Mohamed Hegazy 562abf333a Follow up on #16223 cleaning up Array declarations (#18116)
* Follow up on #16223, Remove generic signatures from Array, ReadOnlyArray and TypedArrays

* Remove test

* Accept baselines

* Remove invalid `this: void` in callbacks

* accept baselines
2017-08-30 10:22:02 -07:00
Andy 54af8aa945 Array arguments to concat should be ReadonlyArrays (#17806) 2017-08-16 14:32:14 -07:00
Homa Wong e8f674fafb Update es5.d.ts 2017-07-18 00:58:05 -07:00
Mohamed Hegazy a3f39ece62 Fix #16521: mark thisArg as optional in typed array map function (#16526) 2017-06-14 11:58:21 -07:00
Mohamed Hegazy a76b4b1f28 Array cleanup (#16223)
* Fix for #13840: Remove map tuple overloads

* Coalesce signatures on array that use this args

* Remove generic signatures

* Add comments to toLocalString

* clean up typed array interfaces
2017-06-04 14:26:18 -07:00
Ron Buckton 578826cd61 Adds definitions for the es2017 Atomics global object 2017-05-10 17:19:26 -07:00
Reiner Dolp eb36455c8b fix issue 15275 2017-04-19 19:37:37 +01:00
Reiner Dolp bb1f8f17db fix issue 10452 2017-04-19 19:36:19 +01:00
Mohamed Hegazy a9c015a56a Fix #15184: Use void and not undefined for this parameter types in the library 2017-04-13 16:25:48 -07:00
Andy Hanson 0152e8c4bb Fix lint scripts 2017-03-20 09:58:37 -07:00
Andy Hanson 2305c10a65 Fix lint errors 2017-03-17 13:54:18 -07:00
falsandtru d86976a9ef Convert overloads to unions 2017-03-14 08:06:00 +09:00
e-cloud cedad974d2 fix: add generic info for methods with thisArg of built-in classes
when enabling `noImplicitThis`, if assing this argument for
methods like `array.forEach` will cause compilation error.
This commit fixes it.

fix #12548
2017-03-09 11:52:54 +08:00
Anders Hejlsberg 7561cdf6bf Add ThisType<any> to Object.{create|defineProperty|defineProperties} 2017-03-01 17:16:09 -08:00
Anders Hejlsberg ee7b93c1a0 Merge branch 'master' into contextualThisType 2017-02-28 09:52:03 -08:00
Mohamed Hegazy a89c62a268 Fix #14136: Make Object.create return any all the time 2017-02-17 16:47:51 -08:00
Anders Hejlsberg fe32bb7642 Merge branch 'master' into contextualThisType 2017-02-16 20:15:55 -08:00
Anders Hejlsberg 8cd6c5d8eb Introduce ThisType<T> marker interface 2017-02-16 17:03:39 -08:00
Ron Buckton 23216f9ba1 Merge branch 'master' into genericDefaults 2017-02-14 19:19:18 -08:00
Mohamed Hegazy ae02db4950 Merge pull request #13936 from Microsoft/FixObjectCreate
Fix #13932: Change the order of overloads and allow union for `Object.create`
2017-02-14 13:29:41 -08:00
Mohamed Hegazy b3bb8ae996 Merge pull request #14000 from mattmccutchen/lib-string-replace
lib: Fix documentation of String.replace first parameter.
2017-02-14 11:39:12 -08:00
Mohamed Hegazy 6feafc9483 Remove extra overload 2017-02-13 20:49:37 -08:00
Mohamed Hegazy d7ae0df647 Move interface Promise<T> declaration to es5.d.ts 2017-02-13 12:50:44 -08:00
Matt McCutchen ecfa0de449 lib: Fix documentation of String.replace first parameter.
The documentation incorrectly suggested that if the first parameter is a
string, it is interpreted as a regular expression.
2017-02-10 16:28:00 -05:00
Mohamed Hegazy ab60d319b2 Fix #13932: Change the order of overloads and allow union for Object.create 2017-02-07 14:07:55 -08:00
Ron Buckton b58ef9e932 Merge branch 'master' into genericDefaults 2017-01-30 14:32:00 -08:00
Ron Buckton 442f5408b6 Updated Promise and PromiseLike to use defaults 2017-01-13 23:48:20 -08:00
Herrington Darkholme e8af1d285b update declaration file to use intrinsic object type 2017-01-08 18:31:56 +08:00
Mohamed Hegazy 9865a17c48 Merge pull request #11222 from kitsonk/array-slice-typings
Improve Array.prototype.splice typing
2016-12-30 14:28:15 -08:00
Mohamed Hegazy 15d870bdcf Use Function instead of call and construct signatures 2016-11-23 10:56:42 -08:00
Mohamed Hegazy 60395565e6 Handel call and construct signatures 2016-11-23 09:48:25 -08:00
Mohamed Hegazy 72df02cbbd Add function 2016-11-21 23:27:18 -08:00
Mohamed Hegazy 8a334ac00d Add special handeling for function and array in Object.freeze 2016-11-21 23:13:22 -08:00
Anders Hejlsberg 854a20f1fe Update Record<K, T> type 2016-11-21 11:42:21 -08:00
Anders Hejlsberg d32196ff36 Add predefined mapped types and revise Object.freeze 2016-11-15 12:14:46 -08:00
Mohamed Hegazy 2cd404038e Port fix in https://github.com/Microsoft/TypeScript/pull/11293 to correct file 2016-10-13 17:26:12 -07:00
Daniel Rosenwasser 7f3db5cf18 Added overloads for 'map' on tuple types. 2016-09-29 00:41:06 -07:00
Kitson Kelly 723ffab8df
Improve Array.prototype.slice typing 2016-09-28 21:50:33 +01:00
Mohamed Hegazy 10b3d73324 Merge pull request #10917 from Salasar/Fix10843
Fix 10843: Change Array.prototype.findIndex method definition according to ES6 spec
2016-09-15 09:18:16 -07:00
Rostislav Galimsky df5e176e17 update findIndex for es5 typed arrays 2016-09-15 08:39:45 +03:00
Ron Buckton 3e1da93d6e Merge pull request #10448 from Microsoft/improvePromiseType
Improve Promise type definition
2016-09-14 11:58:25 -07:00
Mohamed Hegazy 2f9879c45e Update other defintions of findIndex 2016-09-13 22:41:40 -07:00
Jeffrey Morlan 48a610c34f Fix ECMA-402 declarations (issue #10618)
1. Make String.prototype.localeCompare's `locales` parameter optional,
   so `undefined` is allowed.
2. Declare the `locales` parameter as a `string | string[]` union
   instead of using overloads. Having separate overloads for `string`
   and `string[]` unnecessarily prevents passing a `string | string[]`.
   (These overloads predate the introduction of union types.)
2016-09-10 12:25:39 -07:00
Ron Buckton 9d4219acf1 Adjust overloads to fix #10524. 2016-09-06 15:23:11 -07:00
Mohamed Hegazy a63c1c8ab2 Merge pull request #10027 from maiermic/type-guards-in-Array.prototype.filter
add Array.prototype.filter signature with type guard
2016-09-06 12:59:29 -07:00
Nathan Shively-Sanders ce5e2078ee Improve ReadonlyArray<T>.concat to match Array<T>
The Array-based signature was incorrect and also out-of-date.
2016-08-16 11:29:09 -07:00
Michael dbd8dd5c88 add Array.prototype.filter signature with type guard 2016-07-29 15:56:33 +02:00
Nathan Shively-Sanders 09f518243d Re-add concat overload to support inferring tuples 2016-07-27 15:33:36 -07:00
Daniel Rosenwasser 4de0a05402 Make TemplateStringsArray completely immutable. 2016-07-07 11:52:07 -07:00
Mohamed Hegazy 29985f33b7 Update language in comment 2016-07-05 16:11:22 -07:00
Yui 19c141aefe Fix PromiseLike to be compatible with es6-promise (#9484) 2016-07-02 21:50:13 -07:00
Ron Buckton fb9806b5f9 Updates type definitions for Promise and PromiseLike, fixes issues in async functions due to introduction of never type.
Fixes #9193.
2016-06-15 17:36:27 -07:00
york yao f5ab9d7289 change type definition for Object.create 2016-06-06 07:22:37 +08:00
Mohamed Hegazy f1662f8a18 Fix #8729: Make JSON.stringify accept null and undefined replacers 2016-05-21 12:59:09 -07:00
Juan Luis Boya García 5fb68da1ad Modified all other findIndex() definitions 2016-05-20 12:17:15 +02:00
Noj Vek 94d8888b09 Fix #8582: Add Error.prototype.stack definition 2016-05-14 17:29:04 -07:00
Arnavion 8bb75ec3da {Array, TypedArray}.{copyWithin, fill, sort} return this. 2016-05-07 16:28:15 -07:00
Mohamed Hegazy b6e98e52c6 Fix #8338: add signatures to RegExp constructor accepting RegExp 2016-04-28 14:48:53 -07:00
Nathan Shively-Sanders 465e9c82ff Revert Function.bind/apply/call this-overloads 2016-04-28 08:48:08 -07:00