From 71f00d1d713b4686ca69b627c2d5ba9965bd7a91 Mon Sep 17 00:00:00 2001 From: thisisrandy Date: Mon, 13 Jun 2022 14:31:30 -0700 Subject: [PATCH 1/6] Note that object literals may only specify known properties Re: microsoft/TypeScript#49500 --- .../documentation/copy/en/reference/Type Compatibility.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/documentation/copy/en/reference/Type Compatibility.md b/packages/documentation/copy/en/reference/Type Compatibility.md index 8a8e39e4678c..6151bfea0e6d 100644 --- a/packages/documentation/copy/en/reference/Type Compatibility.md +++ b/packages/documentation/copy/en/reference/Type Compatibility.md @@ -70,6 +70,14 @@ greet(dog); // OK Note that `dog` has an extra `owner` property, but this does not create an error. Only members of the target type (`Pet` in this case) are considered when checking for compatibility. +Be aware, however, that [object literals](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html#other-important-typescript-types) +may only specifiy known properties. For example, because we have explicitly specified that `dog` is +of type `Pet`, the following code is invalid: + +```ts +let dog: Pet = { name: "Lassie", owner: "Rudd Weatherwax" }; // Error +``` + This comparison process proceeds recursively, exploring the type of each member and sub-member. ## Comparing two functions From faea8e81e74139bf1292b420a97f0ea58643953e Mon Sep 17 00:00:00 2001 From: Randy West Date: Fri, 19 May 2023 19:40:09 -0700 Subject: [PATCH 2/6] Fix typo --- packages/documentation/copy/en/reference/Type Compatibility.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/documentation/copy/en/reference/Type Compatibility.md b/packages/documentation/copy/en/reference/Type Compatibility.md index 6151bfea0e6d..07581bbc500a 100644 --- a/packages/documentation/copy/en/reference/Type Compatibility.md +++ b/packages/documentation/copy/en/reference/Type Compatibility.md @@ -71,7 +71,7 @@ Note that `dog` has an extra `owner` property, but this does not create an error Only members of the target type (`Pet` in this case) are considered when checking for compatibility. Be aware, however, that [object literals](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html#other-important-typescript-types) -may only specifiy known properties. For example, because we have explicitly specified that `dog` is +may only specify known properties. For example, because we have explicitly specified that `dog` is of type `Pet`, the following code is invalid: ```ts From 045b76dbe5c3954b3ce4547b65e41b807770cb28 Mon Sep 17 00:00:00 2001 From: Randy West Date: Fri, 19 May 2023 19:42:20 -0700 Subject: [PATCH 3/6] Link to excess property checks docs --- packages/documentation/copy/en/reference/Type Compatibility.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/documentation/copy/en/reference/Type Compatibility.md b/packages/documentation/copy/en/reference/Type Compatibility.md index 07581bbc500a..4dee7c96bea4 100644 --- a/packages/documentation/copy/en/reference/Type Compatibility.md +++ b/packages/documentation/copy/en/reference/Type Compatibility.md @@ -70,7 +70,7 @@ greet(dog); // OK Note that `dog` has an extra `owner` property, but this does not create an error. Only members of the target type (`Pet` in this case) are considered when checking for compatibility. -Be aware, however, that [object literals](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-func.html#other-important-typescript-types) +Be aware, however, that [object literals](https://www.typescriptlang.org/docs/handbook/2/objects.html#excess-property-checks) may only specify known properties. For example, because we have explicitly specified that `dog` is of type `Pet`, the following code is invalid: From ab15264086a9f7d344916c1926f2c4fe5a3bcd81 Mon Sep 17 00:00:00 2001 From: thisisrandy Date: Sat, 20 May 2023 18:48:24 -0700 Subject: [PATCH 4/6] Move link to more relevant part of sentence Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com> --- .../documentation/copy/en/reference/Type Compatibility.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/documentation/copy/en/reference/Type Compatibility.md b/packages/documentation/copy/en/reference/Type Compatibility.md index 4dee7c96bea4..7a215c4ccbf5 100644 --- a/packages/documentation/copy/en/reference/Type Compatibility.md +++ b/packages/documentation/copy/en/reference/Type Compatibility.md @@ -70,8 +70,8 @@ greet(dog); // OK Note that `dog` has an extra `owner` property, but this does not create an error. Only members of the target type (`Pet` in this case) are considered when checking for compatibility. -Be aware, however, that [object literals](https://www.typescriptlang.org/docs/handbook/2/objects.html#excess-property-checks) -may only specify known properties. For example, because we have explicitly specified that `dog` is +Be aware, however, that object literals [may only specify known properties](https://www.typescriptlang.org/docs/handbook/2/objects.html#excess-property-checks). +For example, because we have explicitly specified that `dog` is of type `Pet`, the following code is invalid: ```ts From dbbcdc872047be00f6cc82b846ae105e15e6618a Mon Sep 17 00:00:00 2001 From: Randy West Date: Sat, 20 May 2023 18:47:09 -0700 Subject: [PATCH 5/6] Merge same-subject paragraphs --- .../documentation/copy/en/reference/Type Compatibility.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/documentation/copy/en/reference/Type Compatibility.md b/packages/documentation/copy/en/reference/Type Compatibility.md index 7a215c4ccbf5..e22a1a8983fd 100644 --- a/packages/documentation/copy/en/reference/Type Compatibility.md +++ b/packages/documentation/copy/en/reference/Type Compatibility.md @@ -68,7 +68,9 @@ greet(dog); // OK ``` Note that `dog` has an extra `owner` property, but this does not create an error. -Only members of the target type (`Pet` in this case) are considered when checking for compatibility. +Only members of the target type (`Pet` in this case) are considered when +checking for compatibility. This comparison process proceeds recursively, +exploring the type of each member and sub-member. Be aware, however, that object literals [may only specify known properties](https://www.typescriptlang.org/docs/handbook/2/objects.html#excess-property-checks). For example, because we have explicitly specified that `dog` is @@ -78,8 +80,6 @@ of type `Pet`, the following code is invalid: let dog: Pet = { name: "Lassie", owner: "Rudd Weatherwax" }; // Error ``` -This comparison process proceeds recursively, exploring the type of each member and sub-member. - ## Comparing two functions While comparing primitive types and object types is relatively straightforward, the question of what kinds of functions should be considered compatible is a bit more involved. From ae7fcd2b80f12eb2a23b1c5499874540fd5a4061 Mon Sep 17 00:00:00 2001 From: thisisrandy Date: Mon, 22 May 2023 12:54:28 -0700 Subject: [PATCH 6/6] Make link relative Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com> --- packages/documentation/copy/en/reference/Type Compatibility.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/documentation/copy/en/reference/Type Compatibility.md b/packages/documentation/copy/en/reference/Type Compatibility.md index e22a1a8983fd..936225517e75 100644 --- a/packages/documentation/copy/en/reference/Type Compatibility.md +++ b/packages/documentation/copy/en/reference/Type Compatibility.md @@ -72,7 +72,7 @@ Only members of the target type (`Pet` in this case) are considered when checking for compatibility. This comparison process proceeds recursively, exploring the type of each member and sub-member. -Be aware, however, that object literals [may only specify known properties](https://www.typescriptlang.org/docs/handbook/2/objects.html#excess-property-checks). +Be aware, however, that object literals [may only specify known properties](/docs/handbook/2/objects.html#excess-property-checks). For example, because we have explicitly specified that `dog` is of type `Pet`, the following code is invalid: