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

chore: add & fix type definitions for gatsby, gatsby-link, gatsby-source-fs #13619

Merged
merged 9 commits into from
Apr 30, 2019
Merged
2 changes: 1 addition & 1 deletion docs/docs/gatsby-link.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const AreYouSureLink = () => (

Video hosted on [egghead.io][egghead].

Sometimes you need to navigate to pages programatically, such as during form submissions. In these cases, `Link` won’t work.
Sometimes you need to navigate to pages programmatically, such as during form submissions. In these cases, `Link` won’t work.

_**Note:** `navigate` was previously named `navigateTo`. `navigateTo` is deprecated in Gatsby v2 and will be removed in the next major release._

Expand Down
2 changes: 1 addition & 1 deletion examples/using-typescript/src/utils/typography.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export declare const rhythm: (a: number) => number;
export declare const rhythm: (a: number) => number
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"postmarkdown": "prettier --write \"starters/**/*.md\"",
"plop": "plop",
"prebootstrap": "yarn",
"prettier": "prettier \"**/*.{md,css,scss,yaml,yml}\"",
"prettier": "prettier \"**/*.{md,css,scss,yaml,yml,ts}\"",
"publish": "node scripts/check-publish-access && lerna publish",
"publish-canary": "lerna publish --canary --yes",
"publish-next": "lerna publish --npm-tag=next --bump=prerelease",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-image/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface GatsbyImageProps {
alt?: string
className?: string | object
critical?: boolean
crossOrigin?: string | boolean;
crossOrigin?: string | boolean
style?: object
imgStyle?: object
placeholderStyle?: object
Expand Down
35 changes: 34 additions & 1 deletion packages/gatsby-link/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,56 @@ import * as React from "react"
import { NavigateFn, LinkProps } from "@reach/router"

export interface GatsbyLinkProps<TState> extends LinkProps<TState> {
/** A class to apply when this Link is active */
activeClassName?: string
/** Inline styles for when this Link is active */
activeStyle?: object
innerRef?: Function
onClick?: (event: React.MouseEvent<HTMLAnchorElement>) => void
/** Class the link as highlighted if there is a partial match via a the `to` being prefixed to the current url */
partiallyActive?: boolean
/** Used to declare that this link replaces the current URL in history with the target */
replace?: boolean
/** The URL you want to link to */
to: string
}

/**
* This component is intended _only_ for links to pages handled by Gatsby. For links to pages on other
* domains or pages on the same domain not handled by the current Gatsby site, use the normal `<a>` element.
*/
export default class GatsbyLink<TState> extends React.Component<
GatsbyLinkProps<TState>,
any
> {}

/**
* Sometimes you need to navigate to pages programmatically, such as during form submissions. In these
* cases, `Link` won’t work.
*/
export const navigate: NavigateFn

/**
* It is common to host sites in a sub-directory of a site. Gatsby lets you set the path prefix for your site.
* After doing so, Gatsby's `<Link>` component will automatically handle constructing the correct URL in
* development and production
*/
export const withPrefix: (path: string) => string

// TODO: Remove navigateTo, push & replace for Gatsby v3
/**
* @deprecated
* TODO: Remove for Gatsby v3
*/
export const push: (to: string) => void

/**
* @deprecated
* TODO: Remove for Gatsby v3
*/
export const replace: (to: string) => void

/**
* @deprecated
* TODO: Remove for Gatsby v3
*/
export const navigateTo: (to: string) => void
1 change: 0 additions & 1 deletion packages/gatsby-plugin-google-analytics/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export class OutboundLink extends React.Component<
OutboundLinkProps & React.HTMLProps<HTMLAnchorElement>,
any
> {}

1 change: 0 additions & 1 deletion packages/gatsby-plugin-google-gtag/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ export class OutboundLink extends React.Component<
OutboundLinkProps & React.HTMLProps<HTMLAnchorElement>,
any
> {}

84 changes: 84 additions & 0 deletions packages/gatsby-source-filesystem/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Node, Store, Cache } from "gatsby"

/**
* @see https://www.gatsbyjs.org/packages/gatsby-source-filesystem/?=files#createfilepath
*/
export function createFilePath(args: CreateFilePathArgs): string

/**
* @see https://www.gatsbyjs.org/packages/gatsby-source-filesystem/?=files#createremotefilenode
*/
export function createRemoteFileNode(
args: CreateRemoteFileNodeArgs
): FileSystemNode

export interface CreateFilePathArgs {
node: Node
getNode: Function
basePath?: string
trailingSlash?: boolean
}

export interface CreateRemoteFileNodeArgs {
url: string
store: Store
cache: Cache
createNode: Function
createNodeId: Function
parentNodeId?: string
auth?: {
htaccess_user: string
htaccess_pass: string
}
httpHeaders?: object
ext?: string
name?: string
}

export interface FileSystemNode extends Node {
wardpeet marked this conversation as resolved.
Show resolved Hide resolved
absolutePath: string
accessTime: string
birthTime: Date
changeTime: string
extension: string
modifiedTime: string
prettySize: string
relativeDirectory: string
relativePath: string
sourceInstanceName: string

// parsed path typings
base: string
dir: string
ext: string
name: string
root: string

// stats
atime: Date
atimeMs: number
birthtime: Date
birthtimeMs: number
ctime: Date
ctimeMs: number
gid: number
mode: number
mtime: Date
mtimeMs: number
size: number
uid: number
}

export interface FileSystemConfig {
resolve: "gatsby-source-filesystem"
options: FileSystemOptions
}

/**
* @see https://www.gatsbyjs.org/packages/gatsby-source-filesystem/?=filesy#options
*/
interface FileSystemOptions {
name: string
path: string
ignore?: string[]
}
3 changes: 2 additions & 1 deletion packages/gatsby-source-filesystem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@
"build": "babel src --out-dir . --ignore **/__tests__",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__"
}
},
"types": "index.d.ts"
}
Loading