From 4723cc4991a0f7dbed9555fc85b45e48d45bd269 Mon Sep 17 00:00:00 2001 From: Filip Maj Date: Mon, 9 Aug 2021 12:19:29 -0400 Subject: [PATCH] Allow use of "as Type" syntax for type assertions in test code. --- .eslintrc.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 3c4a93e08..458ed5a10 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -124,7 +124,7 @@ module.exports = { // Require class properties and methods to explicitly use accessibility modifiers (public, private, protected) '@typescript-eslint/explicit-member-accessibility': 'error', - // Forbids an object literal to appear in a type assertion expression unless its used as a parameter. This + // Forbids an object literal to appear in a type assertion expression unless its used as a parameter (we violate this rule for test code, to allow for looser property matching for objects - more in the test-specific rules section below). This // allows the typechecker to perform validation on the value as an assignment, instead of allowing the type // assertion to always win. // Requires use of `as Type` instead of `` for type assertion. Consistency. @@ -267,6 +267,13 @@ module.exports = { // See https://github.com/slackapi/bolt-js/pull/1012#pullrequestreview-711232738 // for a case of arrow-vs-function syntax coming up for the team 'prefer-arrow-callback': 'off', + + // Unlike non-test-code, where we requireq use of `as Type` instead of `` for type assertion, in test code using the looser `as Type` syntax leads to easier test writing, since only required properties must be adhered to using the `as Type` syntax. + '@typescript-eslint/consistent-type-assertions': ['error', { + assertionStyle: 'as', + objectLiteralTypeAssertions: 'allow', + }], + }, }, ],