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

Incorrect typescript - ITypeInfoDate #33838

Closed
2 tasks done
tonyhallett opened this issue Nov 3, 2021 · 1 comment · Fixed by #33839
Closed
2 tasks done

Incorrect typescript - ITypeInfoDate #33838

tonyhallett opened this issue Nov 3, 2021 · 1 comment · Fixed by #33839
Labels
type: bug An issue or pull request relating to a bug in Gatsby

Comments

@tonyhallett
Copy link
Contributor

Preliminary Checks

Description

example field typed incorrectly

export interface ITypeInfoDate extends ITypeInfo {
  example: string
}

Should be
export interface ITypeInfoDate extends ITypeInfo {
example: string | Date
}

getType will return date for a node field value that is a Date or is a string that looksLikeADate

const getType = (value: unknown, key: string): ValueType | "null" => {
  // Staying as close as possible to GraphQL types
  switch (typeof value) {
    case `number`:
      return is32BitInteger(value) ? `int` : `float`
    case `string`:
      if (key.includes(`___NODE`)) {
        return `relatedNode`
      }
      return looksLikeADate(value) ? `date` : `string` // *********************************
    case `boolean`:
      return `boolean`
    case `object`:
      if (value === null) return `null`
      if (value instanceof Date) return `date` // *****************************************
      if (value instanceof String) return `string`
      if (Array.isArray(value)) {
        if (value.length === 0) {
          return `null`
        }
        return key.includes(`___NODE`) ? `relatedNodeList` : `array`
      }
      if (!Object.keys(value).length) return `null`
      return `object`
    default:
      // bigint, symbol, function, unknown (host objects in IE were typeof "unknown", for example)
      return `null`
  }
}

and for date types the example value is the node field value - a string or a Date

Reproduction Link

Steps to Reproduce

  1. Follow my description

...

Expected Result

typescript is correct

Actual Result

typescript is incorrect

Environment

System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
  Binaries:
    Node: 16.7.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.11 - C:\Program Files\nodejs\yarn.CMD
    npm: 7.21.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (95.0.1020.40)
  npmPackages:
    gatsby: ^3.13.1 => 3.14.2
    gatsby-plugin-mdx: ^2.14.0 => 2.14.0
    gatsby-source-filesystem: ^3.14.0 => 3.14.0
  npmGlobalPackages:
    gatsby-cli: 3.14.0
    gatsby-dev-cli: 3.14.0

Config Flags

No response

@tonyhallett tonyhallett added the type: bug An issue or pull request relating to a bug in Gatsby label Nov 3, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Nov 3, 2021
@tonyhallett tonyhallett changed the title Incorrect typescript Incorrect typescript - ITypeInfoDate Nov 3, 2021
@LekoArts LekoArts removed the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Nov 4, 2021
@LekoArts
Copy link
Contributor

LekoArts commented Nov 4, 2021

Hi, thanks for the issue.

I'll close this one as it's not related to public types but only our internal code. While having correct types everywhere would be nice fixing the internal ones is not our top priority as it normally yields small benefits compared to other things we (and contributors) can work on. If you find them while browsing the code, feel free to open a PR, but I wouldn't recommend hunting for them. Thanks!

@LekoArts LekoArts closed this as completed Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants