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

Allow null for typescript definitions #975

Closed
harvestnide opened this issue Jul 13, 2022 · 0 comments
Closed

Allow null for typescript definitions #975

harvestnide opened this issue Jul 13, 2022 · 0 comments
Labels
good first issue Good for newcomers

Comments

@harvestnide
Copy link

Duplicate of #840 - which was closed by stale bot

Describe the bug
With strict-null check enabled - you cannot use null as prop for any meta block. All my meta fields are coming from Static/ServerSide Props and there is a catch - next refuses to serialize undefined, meaning that I have to either filter out all undefined values from objects (and there is no easy way to do it recursively and type-safe), or replace them with 0 / empty string (depending on field type).

Reproduction

import type {  OpenGraphMedia } from 'next-set/lib/types';

/*
TS2322: Type 'number | null' is not assignable to type 'number | undefined'.   Type 'null' is not assignable to type 'number | undefined'.  
The expected type comes from property 'width' which is declared here on type 'OpenGraphMedia'
*/
const images: OpenGraphMedia = {
  url: img.sourceUrl,
  width: img.mediaDetails?.width || null,
  height: img.mediaDetails?.height || null,
};

Additional context
I checked couple of files in this repo and it seems like value is implicitly typecasted to boolean, and null is falsy in a same way undefined is. Of course, some investigation is required, but it seems like an extremely easy fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants