Skip to content

Isolated declarations uses type information when emitting computed object keys Β #58533

Open
@lucacasonato

Description

@lucacasonato

πŸ”Ž Search Terms

  • isolated declarations
  • computed keys
  • object literals

πŸ•— Version & Regression Information

5.5.0-dev.20240514

⏯ Playground Link

https://www.typescriptlang.org/play/?isolatedDeclarations=true&ts=5.5.0-dev.20240514#code/KYDwDg9gTgLgBAYwgOwM7wNLAJ5wLxwBEMAFsFtoQNwBQNAJsAgDYCGUwcA5sxAEatmcAN4044uKEixEKdHADivAcwr4ipYEv6CKhMRKnR4SNPACqyAJYBHAK7AAytgC2fCMwBccO9fudUV3dmWglJcGNZMzgAORRLWwdnNw9vQJSQmgBfOiMZU3kAQXVRMIBtCgBdbxgoBwAaA3Ey5OCAOhgIR1qrZC4AFVYuargAM0FUYEbyhP9WjxHx5knpiTLtFSrvJZXsmiA

πŸ’» Code

export const Key = "theKey";

declare global {
    export const GlobalKey = "theGlobalKey"
    export const UniqueSymbol: unique symbol;
    export const NonUniqueSymbol: symbol;
}

export const A = {
    [Key]: true,
    [Symbol.toStringTag]: false,
    [UniqueSymbol]: false,
    [GlobalKey]: false,
}

πŸ™ Actual behavior

TypeScript is emitting the computed property keys with type information that can not be determined without a type checker.

export declare const Key = "theKey";
declare global {
    export const GlobalKey = "theGlobalKey";
    export const UniqueSymbol: unique symbol;
    export const NonUniqueSymbol: symbol;
}
export declare const A: {
    theKey: boolean;
    [Symbol.toStringTag]: boolean;
    [UniqueSymbol]: boolean;
    theGlobalKey: boolean;
};

πŸ™‚ Expected behavior

export declare const Key = "theKey";
declare global {
    export const GlobalKey = "theGlobalKey";
    export const UniqueSymbol: unique symbol;
    export const NonUniqueSymbol: symbol;
}
export declare const A: {
    [Key]: true,
    [Symbol.toStringTag]: false,
    [UniqueSymbol]: false,
    [GlobalKey]: false,
};

Additional information about the issue

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Declaration EmitThe issue relates to the emission of d.ts filesDomain: Isolated DeclarationsRelated to the --isolatedDeclarations compiler flagPossible ImprovementThe current behavior isn't wrong, but it's possible to see that it might be better in some cases

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions