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

Add strict null checks to @pixi/ticker #10087

Open
wants to merge 4 commits into
base: v7.x
Choose a base branch
from

Conversation

8times12
Copy link

@8times12 8times12 commented Jan 9, 2024

Description of change

Ref #8852

I have made the following adjustments to resolve the strict null check errors occurring under the packages/ticker directory.

packages/ticker/src/TickerPlugin.ts

  • Made _ticker and ticker nullable and added optional chaining when referenced.

packages/ticker/src/TickerListener.ts

  • Due to a circular reference issue, defined TickerCallback within this file.
  • In the emit method, to enable type inference for the fn property, set the type of TickerCallback to a union type.
  • To make the type definition more strict, changed the type argument T of the class TickerListener from any to Record<string, any> | null.
    - export class TickerListener<T = any>
    + TickerListenerContext = Record<string, any> | null
    + export class TickerListener<T extends TickerListenerContext = TickerListenerContext>
  • Integrated the definitions of the properties fn, context, priority, and once with the constructor's parameter definitions. This prevents redundant type management between the properties and constructor parameters. Additionally, since null is set to fn and context within the destroy method, made them nullable.
    - public priority: number;
    - private fn: TickerCallback<T>;
    - private context: T;
    - private once: boolean;
    - constructor(fn: TickerCallback<T>, context: T = null, priority = 0, once = false)
    - {
    -     this.fn = fn;
    -     this.context = context;
    -     this.priority = priority;
    -     this.once = once;
    + constructor(
    +     private fn: TickerCallback<T> | null,
    +     private context: T | null = null,
    +     public priority = 0,
    +     private once = false)

packages/ticker/src/Ticker.ts

  • Since null is set to _head and _requestId within the destroy method, made them nullable.
  • Added null check processing for the nullable _head.
Pre-Merge Checklist
  • Tests and/or benchmarks are included
  • Documentation is changed or added
  • Lint process passed (npm run lint)
  • Tests passed (npm run test)

Copy link

codesandbox-ci bot commented Jan 10, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1341ae4:

Sandbox Source
pixi.js-sandbox Configuration

@8times12 8times12 changed the title 【WIP】Add strict null checks to @pixi/ticker Add strict null checks to @pixi/ticker Jan 10, 2024
@Zyie Zyie deleted the branch pixijs:v7.x March 5, 2024 17:16
@Zyie Zyie closed this Mar 5, 2024
@Zyie Zyie reopened this Mar 5, 2024
@Zyie Zyie changed the base branch from dev to v7.x March 5, 2024 18:05
@Zyie Zyie added the v7 label Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants