- {_id === '_new' ? (
-
+ {_id === '_new' && session !== null ? (
+
) : (
= ({ item, columns, collections }) => {
const { data: swrItem } = useSWR('/api/item/' + item._id, {
fallbackData: item,
})
- item = swrItem || item
+ item = (swrItem as Item) || item
item.stars = item.stars || 0
const { data: swrColumns } = useSWR('/api/columns', {
fallbackData: columns,
})
- columns = swrColumns || columns
+ columns = (swrColumns as Column[]) || columns
const { data: swrCollections } = useSWR('/api/collections', {
fallbackData: collections,
})
- collections = (swrCollections || collections).filter((t) =>
+ collections = ((swrCollections as Collection[]) || collections).filter((t) =>
t.items.includes(item._id)
)
const {
@@ -58,7 +58,9 @@ const Item: FC = ({ item, columns, collections }) => {
array: arrayColumns,
text: textColumns,
} = splitColumnsIntoTypes(
- Object.keys(item.data).map((k) => columns.find((c) => c._id === k)),
+ Object.keys(item.data)
+ .map((k) => columns.find((c) => c._id === k))
+ .filter((column) => typeof column !== 'undefined'),
item.data
)
diff --git a/pages/library/[id].tsx b/pages/library/[id].tsx
index c746808f..6b0e83eb 100644
--- a/pages/library/[id].tsx
+++ b/pages/library/[id].tsx
@@ -33,25 +33,25 @@ const Library: FC = ({ library, collections, items, columns }) => {
const [showCollections, setShowCollections] = useState(false)
const { data: swrLibrary } = useSWR('/api/library/' + library._id)
- library = swrLibrary || library
+ library = (swrLibrary as Library) || library
const { data: swrCollections } = useSWR('/api/collections')
- collections = swrCollections || collections
+ collections = (swrCollections as Collection[]) || collections
const libraryCollections = library.collections
.map((collectionId) =>
collections.find((collection) => collection._id === collectionId)
)
- .filter((collection) => collection)
+ .filter((collection) => typeof collection !== 'undefined')
const collectionsItems = [].concat.apply(
[],
libraryCollections.map((collection) => collection.items)
)
const { data: swrItems } = useSWR('/api/items')
- items = swrItems || items
+ items = (swrItems as Item[]) || items
const hotFixLibraryItems = items.filter((i) =>
collectionsItems.some((item) => i._id === item)
)
const { data: swrColumns } = useSWR('/api/columns')
- columns = swrColumns || columns
+ columns = (swrColumns as Column[]) || columns
return (
<>
diff --git a/pages/list/[id].tsx b/pages/list/[id].tsx
index 4dbd2269..8e189891 100644
--- a/pages/list/[id].tsx
+++ b/pages/list/[id].tsx
@@ -31,11 +31,11 @@ const List: FC = ({ list, owner, allItems, columns }) => {
const { data: swrList } = useSWR('/api/list/' + list._id, {
fallbackData: list,
})
- list = swrList || list
+ list = (swrList as List) || list
const { data: swrOwner } = useSWR('/api/user/' + owner.uid, {
fallbackData: owner,
})
- owner = swrOwner || owner
+ owner = (swrOwner as User) || owner
//let adminInfo
if (isAdmin(session)) {
//adminInfo = owner
@@ -48,15 +48,15 @@ const List: FC = ({ list, owner, allItems, columns }) => {
const { data: swrItems } = useSWR('/api/items', {
fallbackData: allItems,
})
- allItems = swrItems || allItems
+ allItems = (swrItems as Item[]) || allItems
const { data: swrColumns } = useSWR('/api/columns', {
fallbackData: columns,
})
- columns = swrColumns || columns
+ columns = (swrColumns as Column[]) || columns
- const items = (list.items || []).map((itemId) =>
- allItems.find((item) => item._id === itemId)
- )
+ const items = (list.items || [])
+ .map((itemId) => allItems.find((item) => item._id === itemId))
+ .filter((item) => typeof item !== 'undefined')
const title = owner.name + "'s list " + list.name
return (
diff --git a/pages/user/[id].tsx b/pages/user/[id].tsx
index 23db4be8..ef5fb9d9 100644
--- a/pages/user/[id].tsx
+++ b/pages/user/[id].tsx
@@ -32,7 +32,7 @@ const User: FC = ({ user, lists, items, columns }) => {
const { data: swrUser } = useSWR('/api/user/' + user.uid, {
fallbackData: user,
})
- user = swrUser || user
+ user = (swrUser as User) || user
let adminInfo
if (isAdmin(session)) {
adminInfo = user
@@ -45,20 +45,20 @@ const User: FC = ({ user, lists, items, columns }) => {
const { data: swrColumn } = useSWR('/api/columns', {
fallbackData: columns,
})
- columns = swrColumn || columns
+ columns = (swrColumn as Column[]) || columns
const { data: swrItem } = useSWR('/api/items', {
fallbackData: items,
})
- items = swrItem || items
- const userFav = user.favs.map((itemId) =>
- items.find((item) => item._id === itemId)
- )
+ items = (swrItem as Item[]) || items
+ const userFav = user.favs
+ .map((itemId) => items.find((item) => item._id === itemId))
+ .filter((item) => typeof item !== 'undefined')
const { data: swrLists } = useSWR('/api/lists', {
fallbackData: lists,
})
- lists = swrLists || lists
+ lists = (swrLists as List[]) || lists
const userLists = lists.filter((list) => list.owner === user.uid)
- const followLists = (swrLists || lists).filter((list) =>
+ const followLists = ((swrLists as List[]) || lists).filter((list) =>
user.followLists.includes(list._id)
)
diff --git a/pages/validate-api.tsx b/pages/validate-api.tsx
index cefb6527..a0ca001e 100644
--- a/pages/validate-api.tsx
+++ b/pages/validate-api.tsx
@@ -27,7 +27,7 @@ export default function ValidateApi() {
secret === '' ? '' : ' is-' + (validSecret ? '' : 'in') + 'valid'
// requested data
- const [data, setData] = useState([])
+ const [data, setData] = useState([])
return (
<>
diff --git a/tsconfig.json b/tsconfig.json
index 89305457..ff90114c 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,7 +1,11 @@
{
"compilerOptions": {
"target": "es2017",
- "lib": ["dom", "dom.iterable", "esnext"],
+ "lib": [
+ "dom",
+ "dom.iterable",
+ "esnext"
+ ],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
@@ -13,8 +17,21 @@
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
- "incremental": true
+ "incremental": true,
+ "strictNullChecks": true,
+ "plugins": [
+ {
+ "name": "next"
+ }
+ ]
},
- "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
- "exclude": ["node_modules"]
+ "include": [
+ "next-env.d.ts",
+ "**/*.ts",
+ "**/*.tsx",
+ ".next/types/**/*.ts"
+ ],
+ "exclude": [
+ "node_modules"
+ ]
}