Skip to content

Commit

Permalink
feat: add new esnext types (denoland#11627)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Aug 10, 2021
1 parent 453dfaa commit 465cf9a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ fn create_compiler_snapshot(
"es2021.string",
"es2021.weakref",
"esnext",
"esnext.error",
"esnext.intl",
"esnext.object",
"esnext.promise",
"esnext.string",
"esnext.weakref",
Expand Down
2 changes: 2 additions & 0 deletions cli/dts/lib.esnext.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ and limitations under the License.

/// <reference lib="es2021" />
/// <reference lib="esnext.array" />
/// <reference lib="esnext.error" />
/// <reference lib="esnext.intl" />
/// <reference lib="esnext.object" />
/// <reference lib="esnext.string" />
16 changes: 16 additions & 0 deletions cli/dts/lib.esnext.error.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

/// <reference no-default-lib="true"/>

interface Error {
cause?: any;
}

interface ErrorInit {
cause?: any;
}

interface ErrorConstructor {
new (message?: string, init?: ErrorInit): Error;
(message?: string, init?: ErrorInit): Error;
}
12 changes: 12 additions & 0 deletions cli/dts/lib.esnext.object.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

/// <reference no-default-lib="true"/>

interface ObjectConstructor {
/**
* Determines whether an object has a property with the specified name.
* @param o The target object.
* @param v A property name.
*/
hasOwn(o: object, v: PropertyKey): boolean;
}
13 changes: 12 additions & 1 deletion cli/tests/unit/esnext_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, unitTest } from "./test_util.ts";
import { assert, assertEquals, unitTest } from "./test_util.ts";

// TODO(@kitsonk) remove when we are no longer patching TypeScript to have
// these types available.
Expand All @@ -10,3 +10,14 @@ unitTest(function typeCheckingEsNextArrayString() {
const b = ["a", "b", "c", "d", "e", "f"];
assertEquals(b.at(-1), "f");
});

unitTest(function objectHasOwn() {
const a = { a: 1 };
assert(Object.hasOwn(a, "a"));
assert(!Object.hasOwn(a, "b"));
});

unitTest(function errorCause() {
const e = new Error("test", { cause: "something" });
assertEquals(e.cause, "something");
});
2 changes: 2 additions & 0 deletions cli/tsc/00_typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -37080,6 +37080,8 @@ var ts;
["es2021.promise", "lib.es2021.promise.d.ts"],
["es2021.string", "lib.es2021.string.d.ts"],
["es2021.weakref", "lib.es2021.weakref.d.ts"],
["esnext.object", "lib.esnext.object.d.ts"],
["esnext.error", "lib.esnext.error.d.ts"],
["esnext.array", "lib.esnext.array.d.ts"],
["esnext.symbol", "lib.es2019.symbol.d.ts"],
["esnext.asynciterable", "lib.es2018.asynciterable.d.ts"],
Expand Down

0 comments on commit 465cf9a

Please sign in to comment.