Skip to content

Declaration emit fails to import symbol on function auto-property #56630

Description

@webstrand

🔎 Search Terms

mixin symbol not imported function property

🕗 Version & Regression Information

  • This changed between version 3.7.7 and 3.8.1, it went from working to being an error.
  • This changed between version 4.2.4 and 4.3.2, it went from being an error to invalid.

⏯ Playground Link

https://www.typescriptlang.org/dev/bug-workbench/?#code/PTAEAEBMFMGMBsCGAnRAXAlgewHYC5Q1kBXaAKBAgGcALLAdwFEBbDNCscWhlttaSADEM8aAQw4YADwB0kGWipkMzAA5ZkaUAG9QrKRNABfUADNkWZqABEM4MminrAbjJkEiKlVCCsWUNBS-JLe+hIAFB5eOkYAlDpkoEmgZEZugeqaOj5+xm6U4KYi0DiIzGKgDqYKSu64VFpUAJ5WALygAMotAEZY8OGxZKbEOLCYuHoYBjgAPAAqAUElkN440PSg4TLbKADmVASIOE0A2gC68a0AfKBY3QBWcGhX4d2eFXPx2onJiN0NqDGoCi3gAsotgitQG8qNAEskEaATmEcDJmswzqB2kRSD8kmkEQ40MRkDhQKDUmQUWiWljQOjXGQMhotLoUcYgA

💻 Code

import{mixin}from"./ref";classFooextendsmixin(class{}){}export{Foo}
// @filename: ref.tsconstsym=Symbol()functionmixin<Textendsnew(...args: any[])=>object>(base: T){abstractclassMextendsbase{[mixin.sym]=true}returnM}mixin.sym=sym;export{mixin}

🙁 Actual behavior

The symbol sym is not referenced properly in the emitted .d.ts it is an undefined name, nor is an error thrown:

import{mixin}from"./ref";declareconstFoo_base: (abstractnew(...args: any[])=>{[sym]: boolean;})&{new(): {};};declareclassFooextendsFoo_base{}export{Foo};

🙂 Expected behavior

The symbol sym should be referenced as it's used mixin.sym

import{mixin}from"./ref";declareconstFoo_base: (abstractnew(...args: any[])=>{[mixin.sym]: boolean;})&{new(): {};};declareclassFooextendsFoo_base{}export{Foo};

or an error should be thrown.

Additional information about the issue

From v3.3.3 to v3.7.7 this technique worked as expected. From v3.8.1 to v4.2.4 this technique resulted in a compiler error. And from v4.3.2 onward this technique has emitted invalid code.

This bug surfaced trying to workaround the fact that const sym is not exported and is a private name.

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: Declaration EmitThe issue relates to the emission of d.ts files

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions