Skip to content

types: update scope type annotations to use ScopeType for better type…#3490

Merged
josdejong merged 3 commits into
josdejong:developfrom
JayChang4w:develop
Jun 11, 2025
Merged

types: update scope type annotations to use ScopeType for better type…#3490
josdejong merged 3 commits into
josdejong:developfrom
JayChang4w:develop

Conversation

@JayChang4w
Copy link
Copy Markdown
Contributor

Hi 👋

This PR improves the ScopeType definition by allowing custom Map-like objects, as shown in the example.

Changes

  • Added a MapLike interface for duck-typed scope objects with get, set, has, and keys methods.
  • Updated ScopeType to support either a plain object or a MapLike object.

Why

While reviewing the documentation, I noticed that math.evaluate() supports custom scope objects with map-like behavior. However, the current type definition uses any, which loses type safety in TypeScript.

This change reflects the intended usage from the docs and makes TypeScript support more accurate.

Let me know if there's anything I should adjust. Thanks!

josdejong added a commit that referenced this pull request Jun 11, 2025
… `custom_scope_objects.js` and an internal tool (see #3490)
Copy link
Copy Markdown
Owner

@josdejong josdejong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @JayChang4w , this is a neat improvement!

I made three inline comments, can you have a look at those?

Comment thread types/index.d.ts Outdated
Comment thread types/index.d.ts Outdated
Comment thread test/typescript-tests/testTypes.ts Outdated
…return type

- Renamed ScopeType to MathScope for naming consistency in type definitions.
- Changed the return type of MapLike interface methods for clarity.
Copy link
Copy Markdown
Owner

@josdejong josdejong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates Jay, looks good 👌 .

@josdejong josdejong merged commit d089378 into josdejong:develop Jun 11, 2025
8 checks passed
@josdejong
Copy link
Copy Markdown
Owner

This fix is published now in v14.5.3, thanks again.

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

Successfully merging this pull request may close these issues.

2 participants