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

Properties with type T | undefined can be null #541

Open
samildeli opened this issue Jan 23, 2023 · 0 comments
Open

Properties with type T | undefined can be null #541

samildeli opened this issue Jan 23, 2023 · 0 comments

Comments

@samildeli
Copy link

samildeli commented Jan 23, 2023

CommonUserstate from @types/tmi.js (version 1.8.2) has the following type definition:

export interface CommonUserstate {
    badges?: Badges | undefined;
    'badge-info'?: BadgeInfo | undefined;
    color?: string | undefined;
    "display-name"?: string | undefined;
    emotes?: { [emoteid: string]: string[] } | undefined;
    id?: string | undefined;
    mod?: boolean | undefined;
    turbo?: boolean | undefined;
    'emotes-raw'?: string | undefined;
    'badges-raw'?: string | undefined;
    'badge-info-raw'?: string | undefined;
    "room-id"?: string | undefined;
    subscriber?: boolean | undefined;
    'user-type'?: "" | "mod" | "global_mod" | "admin" | "staff" | undefined;
    "user-id"?: string | undefined;
    "tmi-sent-ts"?: string | undefined;
    flags?: string | undefined;
    [paramater: string]: any;
}

When I log the user state like this (tmi.js version 1.8.5):

client.on('message', (channel: string, tags: tmi.ChatUserstate, message: string) => {
    console.log(tags);
  });

We see that the properties with no data are null instead of undefined:

{
  'badge-info': { subscriber: '7' },
  badges: { subscriber: '6', 'glhf-pledge': '1' },
  'client-nonce': 'xxx',
  color: '#FF69B4',
  'display-name': 'xxx',
  emotes: null,
  'first-msg': false,
  flags: null,
  id: 'xxx',
  mod: false,
  'returning-chatter': false,
  'room-id': 'xxx',
  subscriber: false,
  'tmi-sent-ts': '1674488061999',
  turbo: false,
  'user-id': 'xxx',
  'user-type': null,
  'emotes-raw': null,
  'badge-info-raw': null,
  'badges-raw': null,
  username: 'xxx',
  'message-type': 'chat'
}

Also related, I was wondering if it is possible for all properties to be undefined (or null). Do I need to check all of them or only those that are expected to be null?

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

No branches or pull requests

1 participant