Skip to content

Conversation

@montymxb
Copy link
Member

Fixes a small issue I ran into when bundling web-workers, the internal import of util/types is only available in a nodejs context. This adds in a pair of drop-in functions that are browser-safe, and should still work the same in a node context as they did before.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR makes the codebase browser-compatible by replacing Node.js-specific util/types imports with custom implementations that work in both browser and Node.js environments.

Changes:

  • Added browser-safe isSet and isMap utility functions to utils.ts
  • Updated imports in custom-type.ts and custom-kind.ts to use the new utility functions instead of Node.js util/types

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/typir/src/utils/utils.ts Introduces browser-compatible isSet and isMap functions using instanceof checks with Object.prototype.toString fallbacks
packages/typir/src/kinds/custom/custom-type.ts Replaces util/types import with new browser-safe utilities from utils.ts
packages/typir/src/kinds/custom/custom-kind.ts Replaces util/types import with new browser-safe utilities from utils.ts

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +77 to +79
export function isSet(value: unknown): value is Set<any> {
return value instanceof Set || Object.prototype.toString.call(value) === '[object Set]';
}
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

The dual-check approach may be redundant in most scenarios. The instanceof check should handle both browser and Node.js contexts for native Set objects. The Object.prototype.toString.call() fallback is primarily useful for Sets from different JavaScript realms (e.g., iframes), but this scenario is uncommon. Consider whether the additional check is necessary for your use case, as instanceof Set alone is typically sufficient and more performant.

Copilot uses AI. Check for mistakes.
Comment on lines +85 to +87
export function isMap(value: unknown): value is Map<any, any> {
return value instanceof Map || Object.prototype.toString.call(value) === '[object Map]';
}
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

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

The dual-check approach may be redundant in most scenarios. The instanceof check should handle both browser and Node.js contexts for native Map objects. The Object.prototype.toString.call() fallback is primarily useful for Maps from different JavaScript realms (e.g., iframes), but this scenario is uncommon. Consider whether the additional check is necessary for your use case, as instanceof Map alone is typically sufficient and more performant.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@JohannesMeierSE JohannesMeierSE 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 fix @montymxb!

Note that #97 is a duplicate, since I was too busy for Typir, sorry.

@JohannesMeierSE JohannesMeierSE merged commit 999279b into main Jan 12, 2026
2 checks passed
@JohannesMeierSE JohannesMeierSE added this to the v0.4 milestone Jan 12, 2026
JohannesMeierSE pushed a commit that referenced this pull request Jan 13, 2026
Fixes a small issue I ran into when bundling web-workers, the internal import of `util/types` is only available in a nodejs context. This adds in a pair of drop-in functions that are browser-safe, and should still work the same in a node context as they did before.
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.

3 participants