8000 Add // @ts-ignore to typescript.d.ts AssertClause and AssertEntry entries for API backwards compatibility? Β· Issue #56954 Β· microsoft/TypeScript Β· GitHub
[go: up one dir, main page]

Skip to content
Add // @ts-ignore to typescript.d.ts AssertClause and AssertEntry entries for API backwards compatibility?Β #56954
Closed
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

πŸ” Search Terms

api breaking change interface merge assert clause entry import attribute attributes

βœ… Viability Checklist

⭐ Suggestion

The AssertClause and AssertEntry interfaces in TypeScript 5.3.3 clash with their declarations in typescript-eslint - even after #56485. We don't see a way to resolve this for users. For the sake of backwards compatibility, could the types be given // @ts-ignores so that folks don't have to skipLibCheck?

    /** @deprecated */
+   // @ts-ignore
    interface AssertEntry extends ImportAttribute {
    }
    /** @deprecated */
+   // @ts-ignore
    interface AssertClause extends ImportAttributes {
    }

...and in general, whenever a type is @deprecated, could it be given a // @ts-ignore?

πŸ“ƒ Motivating Example

We haven't been able to figure out a way to fix this for users of typescript-eslint who want to keep skipLibCheck disabled.

I realize how gross it is to suggest // @ts-ignore inside TypeScript's types, but short of moving the types to DefinitelyTyped or patch-package, I'm out of ideas...

πŸ’» Use Cases

typescript-eslint uses interface merging to ensure types for newly-added nodes are present regardless of TypeScript version:

// Workaround to support new TS version features for consumers on old TS versions
// Eg: https://github.com/typescript-eslint/typescript-eslint/issues/2388, https://github.com/typescript-eslint/typescript-eslint/issues/2784
declare module 'typescript' {
  /** @ts-ignore - added in TS 4.5, deprecated and converted to a type-alias in TS 5.3 */
  export interface AssertClause extends ts.Node {}
  /** @ts-ignore - added in TS 4.5, deprecated and converted to a type-alias in TS 5.3 */
  export interface AssertEntry extends ts.Node {}

Paraphrasing @bradzacher's typescript-eslint/typescript-eslint#8047 (comment):

  • TypeScript 4.5 - 5.2 declared AssertClause and AssertEntry with standard interfaces (interface AssertEntry extends Node { ... })
  • TypeScript 5.3 changed them to type aliases (type AssertEntry = ImportAttribute), which broke interface merging in typescript-eslint
  • Make AssertEntry and AssertClause interfacesΒ #56485 -> TypeScript 5.3.3 changed them to interfaces (interface AssertEntry extends ImportAttribute { ... })

...but the 5.3.3 change didn't fix type checking on typescript.d.ts complaints for users. typescript-eslint/typescript-eslint#8047 shows project links & reports from users reporting they need to enable skipLibCheck:

node_modules/typescript/lib/typescript.d.ts:6021:15 - error TS2320: Interface 'AssertEntry' cannot simultaneously extend types 'ImportAttribute' and 'Node'.
  Named property 'kind' of types 'ImportAttribute' and 'Node' are not identical.

6021     interface AssertEntry extends ImportAttribute {
                   ~~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0