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

Simplify and convert with-vercel-fetch example to TypeScript #43403

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions examples/with-vercel-fetch/fetch/browser.js

This file was deleted.

4 changes: 0 additions & 4 deletions examples/with-vercel-fetch/fetch/package.json

This file was deleted.

4 changes: 0 additions & 4 deletions examples/with-vercel-fetch/fetch/server.js

This file was deleted.

10 changes: 10 additions & 0 deletions examples/with-vercel-fetch/github.d.ts
@@ -0,0 +1,10 @@
// For simplicity we are creating our own types here.
// If you want the full types check out:
// https://github.com/octokit/openapi-types.ts
export type Repository = {
id: number
name: string
full_name: string
stargazers_count: number
private: boolean
} & Record<string, unknown>
12 changes: 8 additions & 4 deletions examples/with-vercel-fetch/package.json
Expand Up @@ -6,11 +6,15 @@
"start": "next start"
},
"dependencies": {
"@vercel/fetch": "6.1.0",
"@vercel/fetch": "^6.2.0",
"next": "latest",
"node-fetch": "2.6.7",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"unfetch": "4.2.0"
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/node": "^18.11.9",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"typescript": "^4.9.3"
}
}
19 changes: 0 additions & 19 deletions examples/with-vercel-fetch/pages/index.js

This file was deleted.

21 changes: 21 additions & 0 deletions examples/with-vercel-fetch/pages/index.tsx
@@ -0,0 +1,21 @@
import type { InferGetStaticPropsType } from 'next'
import type { Repository } from '../github'
import createFetch from '@vercel/fetch'

export async function getStaticProps() {
const fetch = createFetch()
const res = await fetch('https://api.github.com/repos/vercel/next.js')
const repo = (await res.json()) as Repository

return { props: { stars: repo.stargazers_count } }
}

export default function HomePage({
stars,
}: InferGetStaticPropsType<typeof getStaticProps>) {
return (
<div>
<p>Next.js has {stars} ⭐️</p>
</div>
)
}
19 changes: 0 additions & 19 deletions examples/with-vercel-fetch/pages/preact.js

This file was deleted.

20 changes: 20 additions & 0 deletions examples/with-vercel-fetch/tsconfig.json
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "github.d.ts"],
"exclude": ["node_modules"]
}