Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin interface is renamed to Plugin$1 and breaks stuff #97

Closed
unxok opened this issue Oct 16, 2024 · 8 comments
Closed

Plugin interface is renamed to Plugin$1 and breaks stuff #97

unxok opened this issue Oct 16, 2024 · 8 comments
Assignees

Comments

@unxok
Copy link
Contributor

unxok commented Oct 16, 2024

Description of issue

It looks like the problem is with dts-bundle-generator, but I couldn't find an existing issue that fully matches this problem.

It appears that the tool is renaming it to Plugin$1 due to it detecting a conflict with the (deprecated) global Plugin. I'm guessing the tool detects the conflict and renames it in the assumption that the obsidian-typings' interface is meaning to extend the global interface or that you will export it with something (in which case it will export it correctly with its true name).

Due to this rename, typescript is only aware that Plugin$1 extends the Component interface and not that it is supposed to be merged with the Plugin class from obsidian.

Minimal repro

import { Plugin, PluginSettingTab } from "obsidian";

export default class MyPlugin extends Plugin {
  onload() {
    this.addSettingTab(new MySettingTab(this)) // type error: MySettingTab is incompatible with PluginSettingTab
  }
}

class MySettingTab extends PluginSettingTab {
  // type error: property "plugin" incompatible with known property from base type
  // because Plugin$1 is not merged with Plugin
  plugin: MyPlugin;
  constructor(plugin: MyPlugin) {
    super(plugin.app, plugin);
    this.plugin = plugin;
  }
}

Workaround

The easiest fix is just to replace all occurrences of "Plugin$1" with "Plugin" and remove the renaming of "Plugin" in the import statement within the types.d.ts file. Obviously this isn't preferred, but I'm guessing the true solution will take some time since it likely is dts-bundle-generator's problem.

@mnaoumov
Copy link
Collaborator

@unxok I don't see an issue with the code you provided.

Please prepare a full example including package.json and tsconfig.json

@unxok
Copy link
Contributor Author

unxok commented Oct 16, 2024

There wouldn't be anything wrong with the code example I provided if obsidian-typings was correct.

The issue is obsidian-typings definition for "Plugin" is renamed to "Plugin$1" by dts-bundle-generator. Because of this, the code example I provided will have typescript errors.

@mnaoumov
Copy link
Collaborator

@unxok

I don't have typescript errors with your code that's why I asked for a complete example

@unxok
Copy link
Contributor Author

unxok commented Oct 17, 2024

@mnaoumov

Ah I see, then the easiest way to see a "complete" example would be just to look at my repo where it's happening and fork it?

Or would you rather I make an entire example plugin to demonstrate the error?

@mnaoumov
Copy link
Collaborator

@unxok I was finally able to reproduce the issue. Working on the fix

@mnaoumov
Copy link
Collaborator

Fixed in https://github.com/Fevol/obsidian-typings/releases/tag/2.2.1-beta.33

@mnaoumov
Copy link
Collaborator

Opened a corresponding issue timocov/dts-bundle-generator#335

@unxok
Copy link
Contributor Author

unxok commented Oct 19, 2024

Nice thanks for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants