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

Error building sample plugin to confirm installation after upgrading to non-deprecated node.js modules #115

Open
devinhedge opened this issue Aug 30, 2024 · 1 comment

Comments

@devinhedge
Copy link

Ran 'git clone https://github.com/obsidianmd/obsidian-sample-plugin.git'
Ran 'npm install --save-dev' and received a deprecation error for server packages.

npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated @humanwhocodes/[email protected]: Use @eslint/config-array instead
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated @humanwhocodes/[email protected]: Use @eslint/object-schema instead

I ran 'npm run dev' and every worked fine. If I upgrade the deprecated modules I receive the following:

I'm building another obsidian.md plugin usnig typescript. Attached is my 'main.ts' file. When I type 'npm run build' I receive the following errors:

src/main.ts:14:2 - error TS2564: Property 'settings' has no initializer and is not definitely assigned in the constructor.

14  settings: MyPluginSettings;
    ~~~~~~~~

src/main.ts:43:4 - error TS2322: Type '(editor: Editor, view: MarkdownView) => void' is not assignable to type '(editor: Editor, ctx: MarkdownView | MarkdownFileInfo) => any'.
  Types of parameters 'view' and 'ctx' are incompatible.
    Type 'MarkdownView | MarkdownFileInfo' is not assignable to type 'MarkdownView'.
      Type 'MarkdownFileInfo' is missing the following properties from type 'MarkdownView': previewMode, currentMode, getViewType, getMode, and 39 more.

43    editorCallback: (editor: Editor, view: MarkdownView) => {
      ~~~~~~~~~~~~~~

  node_modules/obsidian/obsidian.d.ts:726:5
    726     editorCallback?: (editor: Editor, ctx: MarkdownView | MarkdownFileInfo) => any;
            ~~~~~~~~~~~~~~
    The expected type comes from property 'editorCallback' which is declared here on type 'Command'


Found 2 errors in the same file, starting at: src/main.ts:14

This fix resolves the issue.

Explanation:

  1. Property 'settings' has no initializer and is not definitely assigned in the constructor:

This error occurs because TypeScript expects the settings property to be initialized in the constructor or declared with a definite assignment assertion. To fix this, you can initialize settings with a default value or mark it with a definite assignment assertion (!).

  1. Type '(editor: Editor, view: MarkdownView) => void' is not assignable to type '(editor: Editor, ctx: MarkdownView | MarkdownFileInfo) => any':

This error occurs because the type signature for editorCallback in your Command expects the second parameter to be either a MarkdownView or MarkdownFileInfo. However, your callback currently only handles MarkdownView. You'll need to update the type signature to accommodate both types or ensure the correct type handling.

@devinhedge
Copy link
Author

Key Changes:

Settings Initialization:

  • The settings property is now initialized directly with DEFAULT_SETTINGS.

Editor Callback Type Handling:

  • The editorCallback is updated to handle both MarkdownView and MarkdownFileInfo types.

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

1 participant