Skip to content

fix: declare Gleap.setStyles with its positional arguments - #230

Merged
TobiasDuelli merged 2 commits into
masterfrom
fix-setstyles-types
Nov 24, 2026
Merged

TobiasDuelli merged 2 commits into
masterfrom
fix-setstyles-types

Conversation

@TobiasDuelli

Copy link
Copy Markdown
Collaborator

What

index.d.ts has declared Gleap.setStyles with a single object since v6.4.5, but the runtime (src/Gleap.js) takes positional arguments. A call written the way the typings describe throws TypeError: e.substr is not a function on the host page and injects no styles. This PR makes the declaration describe what the runtime accepts. No runtime change.

Before:

function setStyles(styles: {
  primaryColor: string; headerColor: string; buttonColor: string; backgroundColor: string;
  borderRadius?: number; buttonX?: number; buttonY?: number; buttonStyle?: string;
}): void;

After (matches static setStyles(...) and its defaults; JSDoc lists the defaults and the six launcher positions):

function setStyles(
  primaryColor: string, headerColor: string, buttonColor: string,
  backgroundColor?: string,   // "#ffffff"
  borderRadius?: number,      // 20
  buttonX?: number,           // 20
  buttonY?: number,           // 20
  buttonStyle?: string,       // "BOTTOM_LEFT"
  headerColor2?: string,      // headerColor
  headerColor3?: string       // headerColor
): void;

TypeScript projects that call setStyles with an object now get a compile error at that call. That call never worked, so the error points them at a real bug. CHANGELOG.md has an Unreleased entry saying this.

The README does not document setStyles, so it has no object form to correct.

Test

New smoke/typings.spec.mjs compiles smoke/typings.fixture.ts against index.d.ts with the TypeScript compiler API, using the options from npm run typecheck. The fixture has a 3-argument call and a 10-argument call that must compile, and an object-form call marked @ts-expect-error that must not compile. The test went in as its own commit and failed on master for the expected reasons:

"Expected 1 arguments, but got 3.",
"Expected 1 arguments, but got 10.",
"Unused '@ts-expect-error' directive.",

It uses typescript, which is already a devDependency. No new dependency, no script change.

Proof

  • npm run typecheck: exit 0
  • npm run test:smoke: 9 passed, including the new one and "every function index.d.ts declares exists on window.Gleap"
  • node tools/quality/check.mjs: 0 problems
  • npx -y npm@10.9.2 ci --ignore-scripts --dry-run: exit 0
  • npm run build on master and on this branch: all 921 files under build/ and published/ have identical SHA-256 hashes. The build artifacts are not committed.
  • Built browser bundle in Chromium, run locally and not committed: both fixture calls inject .gleap-styles with no page error. The object form throws TypeError: e.substr is not a function.

Not in this PR (typings only, for a follow-up)

  • Runtime functions missing from index.d.ts: openURL, disableQueryParams, checkForUrlParams, disableLocalStorage, triggerCustomAction, startFeedbackFlowWithOptions, startFeedbackFlowNow, buildTourStartUrl, checkForUncompletedTour, startProductTourWithConfig, showBanner, showModal, showNotification
  • startProductTour(tourId) is declared without its optional second parameter checkStartUrl
  • setLiveSite is declared, but the runtime has no such function (it is allow-listed in the smoke test)
  • agent-message-sent, agent-reply-received, agent-error and agent-conversation-created are in the Gleap.on union, but they only fire as gleap-agent-* DOM events on the agent conversation element

🤖 Generated with Claude Code

TobiasDuelli and others added 2 commits November 23, 2026 13:31
… makes

The positional calls the SDK accepts must compile and the object form,
which throws on the page, must not. Fails on master: index.d.ts declares
setStyles with one object.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
index.d.ts declared setStyles with one object since v6.4.5, while the
runtime takes primaryColor, headerColor, buttonColor and seven optional
positional arguments. A call in the declared form threw on the page and
injected no styles. Types and changelog only; no runtime change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TobiasDuelli
TobiasDuelli marked this pull request as ready for review November 23, 2026 16:20
@TobiasDuelli
TobiasDuelli merged commit 364ae64 into master Nov 24, 2026
2 checks passed
@TobiasDuelli
TobiasDuelli deleted the fix-setstyles-types branch November 24, 2026 08:28
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