Skip to content

TS1166 reported for imported symbol as computed property name in generated d.ts #61360

Closed
@jeremymeng

Description

@jeremymeng

🔎 Search Terms

ts1166

🕗 Version & Regression Information

  • This changed between versions 5.7.2 and 5.8.2
  • This changed in commit or PR 61136
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.7.3#code/JYWwDg9gTgLgBAbzsAdgZzAUwMbwL5wBmUEIcARChACaYBcArjMADbkDcAUJ9hOvNgZoYpOAF5k6LLgB0g4aS6dMAD0iw42FgEM0aOAFkAngFEoJKHFUxMKavrMXEnOHADa8kSAC6ACgCUdHDCUKgA5s6urlCYMAxQKBQUXK54nGmcQA

💻 Code

compiling this code with 5.8.2

import { inspect } from "node:util";
const custom = inspect.custom;
export class MyError extends Error {
  [custom](): string {
    return " ";
  }
}

🙁 Actual behavior

generates the d.ts of

declare const custom: symbol;                                                                                                                                                                                              A computed property name in a class property declaration must have a simple literal type or a
export declare class MyError extends Error {                                                                                                                                                                                                                                                'unique symbol' type. [1166]
    [custom]: () => string;
}
export {};
//# sourceMappingURL=restError.d.ts.map

Opening this in editor we are seeing error of

restError… 3 5 error 1166 A computed property name in a class property declaration must have a simple literal type or a 'unique symbol' type. (lsp)

🙂 Expected behavior

d.ts generated by 5.7.2 is slightly different [x: symbol]: () => string; and has no errors

export declare class MyError extends Error {
    [x: symbol]: () => string;
}
//# sourceMappingURL=restError.d.ts.map

Additional information about the issue

every-ts bisect pointing to this commit:

c3ae7c4 is the first bad commit
commit c3ae7c4 (HEAD)
Author: Gabriela Araujo Britto gabrielaa@microsoft.com
Date: Fri Feb 7 10:55:34 2025 -0800

Revert return type narrowing (#61136)

Same issue exists in version 5.9.0-dev.20250305

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions