Skip to content

Replace cases of {} being used to store arbitrary names with Object.create(null) #1121

Closed

Description

@ssalbdivad

I just found a bug with this code:

const nameCounts: Record<string, number | undefined> = {};

export const register = (value: object | symbol): string => {
  const existingName = namesByResolution.get(value);
  if (existingName) return existingName;

  let name = baseNameFor(value);
  if (nameCounts[name]) name = `${name}${nameCounts[name]!++}`;
  else nameCounts[name] = 1;

  registry[name] = value;
  namesByResolution.set(value, name);
  return name;
};

Where attempting to register a function called toString results in a registered name of toStringNaN☠️

We frequently use objects like this to keep track of cached entries. Many of them don't overlap with object method names like toString, but we should review those we have and switch them to Object.create(null) and implement a lint rule if possible.

Activity

  1. added a commit that references this issue on Oct 13, 2026
    23f54d0
  2. ssalbdivad commented on Nov 18, 2026

    @ssalbdivad
    MemberAuthor

    Fixed in 3.0.0-beta.0 (#1728). Try it with npm i arktype@next.

  3. moved this from Backlog to Done (merged or closed) in arktypeioon Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status
      Done (merged or closed)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions