fix some type errors

This commit is contained in:
Thomas Ruoff
2021-02-08 23:18:29 +01:00
parent 78af180567
commit d7478b5e9c
11 changed files with 232 additions and 135 deletions

View File

@@ -13,7 +13,7 @@ class App extends Component {
}
render() {
const state = this.state || {}
const state: Record<string, unknown> = this.state || {}
return (
<div className="home">

View File

@@ -1,19 +0,0 @@
import * as React from 'react'
import ListItem from './ListItem'
import { User } from '../interfaces'
type Props = {
items: User[]
}
const List = ({ items }: Props) => (
<ul>
{items.map((item) => (
<li key={item.id}>
<ListItem data={item} />
</li>
))}
</ul>
)
export default List

View File

@@ -1,16 +0,0 @@
import * as React from 'react'
import { User } from '../interfaces'
type ListDetailProps = {
item: User
}
const ListDetail = ({ item: user }: ListDetailProps) => (
<div>
<h1>Detail for {user.name}</h1>
<p>ID: {user.id}</p>
</div>
)
export default ListDetail

View File

@@ -1,18 +0,0 @@
import React from 'react'
import Link from 'next/link'
import { User } from '../interfaces'
type Props = {
data: User
}
const ListItem = ({ data }: Props) => (
<Link href="/users/[id]" as={`/users/${data.id}`}>
<a>
{data.id}: {data.name}
</a>
</Link>
)
export default ListItem

View File

@@ -1,12 +1,10 @@
function checkStatus(res) {
function checkStatus(res: Response) {
if (res.status < 200 || res.status >= 400) {
throw new Error(`Something went wrong (Status ${res.status}) - I do feel very sorry!`)
}
return res
}
export function generatePdf(state) {
export async function generatePdf(state: Record<string, string>) {
const options = {
method: 'POST',
headers: {
@@ -15,17 +13,19 @@ export function generatePdf(state) {
body: JSON.stringify(state),
}
return fetch('/api/pdf/generate/brief', options)
.then(checkStatus)
.then((res) => res.json())
const response = await fetch('/api/pdf/generate/brief', options)
checkStatus(response)
return response.json()
}
export function getLatest() {
return fetch('/api/pdf/latest')
.then(checkStatus)
.then((res) => res.json())
export async function getLatest() {
const response = await fetch('/api/pdf/latest')
checkStatus(response)
return response.json()
}
export function removeLatest(item) {
return fetch(`/api/pdf/latest/${item.id}`, { method: 'DELETE' }).then(checkStatus)
export async function removeLatest(item: { id: string }) {
const response = await fetch(`/api/pdf/latest/${item.id}`, { method: 'DELETE' })
checkStatus(response)
return response
}