Skip to content

Bug: [explicit-module-boundary-types] allowDirectConstAssertionInArrowFunctions should not error when also using satisfies #10231

Closed
@jleider

Description

@jleider

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.6.3&fileType=.ts&code=FAFwngDgpgBAYgewTAvDA3sGMBmSBcMAziAE4CWAdgOYA0WMARgIamGUCuAto1KfQF8A3MGBQAHhASkQMAMYJKJGM1QwAFAEpUAPg2ZseBIQBEcAPKWT9bCzYwAjACYAzIOZF5ikpqEwA9P4wADwAtKEwACoAFuSeAO7SANaeHjAS0HIgUAAmAHSiGdKyCkqyjGpauvoMRqYWVjZMrITObsACKp6lykTMIHE45FCeiAi%2BAUFhETFxMCDRpAjxqZTppEukBUA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6RAD2MbMroFsA9gBMEiWgCNBsJsICG0QrSKlUGANrhsORNGiDokADRbtwKHPjxBAdwAilaIjL4AwoKbJ8AQWTJd%2BJQeAJJM3nq2AGIyLkGe6GD4cIhgAL6mYAC6WumpQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

type Foo = {
  foo: string,
  bar: number,
};

export const a = () => ({
  foo: "FOOO",
  bar: 123,
}as const); // <-- This works as expected.

export const b = () => ({
  foo: "FOOO",
  bar: 123,
} as const satisfies Foo); // <-- This throws an error.

ESLint Config

module.exports = {
  "rules": {
    "@typescript-eslint/explicit-module-boundary-types": [
      "error",
      { "allowDirectConstAssertionInArrowFunctions": true }
    ]
  }
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

This concerns both explicit-module-boundary-types and explicit-function-return-type rules.

I have a situation where I want to use both as const followed by satisfies. With the rule currently as written as soon as you add a satisfies after an as const the rule will error. Leaving off the satisfies works as expected.

In this scenario, the satisfies Foo provides extra type safety ensuring that a satisfies Foo but still keeping the ability to have explicit type literals for foo: "FOOO" and bar: 123.

Actual Result

The rule should not throw an error when using as const satisfies Foo

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions