Skip to content

Commit

Permalink
Fix typescript errors (#13)
Browse files Browse the repository at this point in the history
* Fix typescript errors
* Move declaration files to regular modules
* Fix arg type
* Make tsconfig self-contained
* Add error on type mismatch

---------

Co-authored-by: Nicolas Ayral Seydoux <[email protected]>
  • Loading branch information
edwardsph and NSeydoux authored Aug 5, 2024
1 parent 85a5b6f commit 7e69e4f
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 18 deletions.
1 change: 1 addition & 0 deletions api/accessGrant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import type { AccessGrant, AccessGrantGroup } from "@/types/accessGrant";
import { makeApiRequest } from "./apiRequest";

export const getAccessGrants = async (): Promise<AccessGrantGroup[]> => {
Expand Down
4 changes: 1 addition & 3 deletions api/apiRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ export const makeApiRequest = async <T>(
return result;
};

export const objectToParams = (
obj: Record<string, string | number | boolean | null | undefined>
): string => {
export const objectToParams = (obj: object): string => {
const params = new URLSearchParams();

Object.entries(obj).forEach(([key, value]) => {
Expand Down
3 changes: 1 addition & 2 deletions api/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export const postFile = async (file: FileObject): Promise<void> => {
const formData = new FormData();
formData.append("file", {
name: file.name,
type:
file.contentType || mime.getType(file.name) || "application/octet-stream",
type: file.type || mime.getType(file.name) || "application/octet-stream",
uri: file.uri,
} as unknown as Blob);

Expand Down
7 changes: 4 additions & 3 deletions app/(tabs)/accesses/[webId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { faEllipsis } from "@fortawesome/free-solid-svg-icons/faEllipsis";
import WebIdDisplay from "@/components/common/WebIdDisplay";
import ConfirmModal from "@/components/common/ConfirmModal";
import Loading from "@/components/LoadingButton";
import type { AccessGrant, AccessGrantGroup } from "@/types/accessGrant";

interface AccessGrantProps {}

Expand All @@ -63,7 +64,7 @@ const Page: React.FC<AccessGrantProps> = () => {
onSuccess: async () => {
setModalVisible(false);
setUpdating(false);
if (selectedRequest.items.length <= 1) {
if (selectedRequest && selectedRequest.items.length <= 1) {
navigation.goBack();
} else {
// eslint-disable-next-line no-console
Expand All @@ -83,7 +84,7 @@ const Page: React.FC<AccessGrantProps> = () => {

useLayoutEffect(() => {
navigation.setOptions({
headerTitle: selectedRequest.ownerName,
headerTitle: selectedRequest?.ownerName,
headerLeft: () => (
<TouchableOpacity
onPress={() => navigation.goBack()}
Expand All @@ -96,7 +97,7 @@ const Page: React.FC<AccessGrantProps> = () => {
<TouchableOpacity
onPress={() => {
setSelectedAG(undefined);
setSelectedWebId(selectedRequest.webId);
setSelectedWebId(selectedRequest?.webId);
bottomSheetModalRef.current?.present();
}}
>
Expand Down
1 change: 1 addition & 0 deletions app/(tabs)/accesses/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useQuery } from "@tanstack/react-query";
import { StyleSheet, View } from "react-native";
import WebIdAccessGrantList from "@/components/accessGrants/WebIdAccessGrantList";
import useRefreshOnFocus from "@/hooks/useRefreshOnFocus";
import type { AccessGrantGroup } from "@/types/accessGrant";

export default function AccessGrantScreen() {
const {
Expand Down
2 changes: 1 addition & 1 deletion app/(tabs)/home/download.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Page: React.FC<FileDetailProps> = () => {
mutation.mutate({
uri: uri as string,
name: fileName,
contentType,
type: contentType as string,
});
goBack();
};
Expand Down
1 change: 1 addition & 0 deletions components/accessGrants/AccessGrantList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import React from "react";
import { FlatList } from "react-native";
import AccessGrantCard from "@/components/accessGrants/AccessGrantCard";
import type { AccessGrant, AccessGrantGroup } from "@/types/accessGrant";

interface AccessGrantListProps {
data: AccessGrantGroup;
Expand Down
1 change: 1 addition & 0 deletions components/accessGrants/WebIdAccessGrantList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { FlatList, StyleSheet, View } from "react-native";
import WebIdAccessGrantCard from "@/components/accessGrants/WebIdAccessGrantCard";
import { ThemedText } from "@/components/ThemedText";
import { Colors } from "@/constants/Colors";
import type { AccessGrantGroup } from "@/types/accessGrant";
import Loading from "../LoadingButton";

interface WebIdAccessGrantListProps
Expand Down
1 change: 1 addition & 0 deletions components/accessGrants/modal/BottomModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { Colors } from "@/constants/Colors";
import { ThemedText } from "@/components/ThemedText";
import IconResourceName from "@/components/common/IconResourceName";
import WebIdDisplay from "@/components/common/WebIdDisplay";
import type { AccessGrant, AccessGrantGroup } from "@/types/accessGrant";

interface BottomModalProps {
accessGrant?: AccessGrant;
Expand Down
4 changes: 4 additions & 0 deletions components/files/BottomModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import * as Sharing from "expo-sharing";
import * as FileSystem from "expo-file-system";
import QRCode from "react-native-qrcode-svg";
import { formatResourceName } from "@/utils/fileUtils";
import type { UserInfo } from "@/constants/user";
import { ThemedText } from "../ThemedText";
import ConfirmModal from "../common/ConfirmModal";

Expand Down Expand Up @@ -67,6 +68,9 @@ const BottomModal: React.FC<BottomModalProps> = ({
const fr = new FileReader();
fr.onload = async () => {
const fileUri = `${FileSystem.documentDirectory}/${fileName}`;
if (typeof fr.result !== "string") {
throw new Error("An error happened while reading the file.");
}
await FileSystem.writeAsStringAsync(fileUri, fr.result?.split(",")[1], {
encoding: FileSystem.EncodingType.Base64,
});
Expand Down
27 changes: 24 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
{
"extends": "expo/tsconfig.base",
"compilerOptions": {
"strict": true,
"module": "esnext",
"paths": {
"@/*": [
"./*"
]
}
},
"allowJs": true,
"esModuleInterop": true,
"jsx": "react-native",
"lib": [
"DOM",
"ESNext"
],
"resolveJsonModule": true,
"target": "ESNext",
"moduleResolution": "node",
},
"include": ["**/*.ts", "**/*.tsx", ".expo/types/**/*.ts", "expo-env.d.ts"]
"include": [
"**/*.ts",
"**/*.tsx",
".expo/types/**/*.ts",
"expo-env.d.ts"
],
"exclude": [
"node_modules",
"babel.config.js",
"metro.config.js",
"jest.config.js"
],
"extends": "expo/tsconfig.base"
}
2 changes: 1 addition & 1 deletion types/WalletFile.d.ts → types/WalletFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
interface WalletFile {
export interface WalletFile {
identifier: string;
fileName: string;
isRDFResource: boolean;
Expand Down
4 changes: 2 additions & 2 deletions types/accessGrant.d.ts → types/accessGrant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//
import type { AccessRequestMode } from "./enums";

interface AccessGrant {
export interface AccessGrant {
uuid: string;
identifier: string;
webId: string;
Expand All @@ -35,7 +35,7 @@ interface AccessGrant {
modes: AccessRequestMode[];
}

interface AccessGrantGroup {
export interface AccessGrantGroup {
webId: string;
logo: string;
ownerName: string;
Expand Down
4 changes: 2 additions & 2 deletions types/accessPrompt.d.ts → types/accessPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
interface AccessPromptQR {
export interface AccessPromptQR {
webId: string;
accessPromptUrl: string;
type: string;
}

interface AccessPromptResource {
export interface AccessPromptResource {
webId: string;
accessPromptUrl: string;
resource: string;
Expand Down
2 changes: 1 addition & 1 deletion types/accessRequest.d.ts → types/accessRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//
import type { AccessRequestMode } from "./enums";

interface AccessRequest {
export interface AccessRequest {
uuid: string;
identifier: string;
webId: string;
Expand Down

0 comments on commit 7e69e4f

Please sign in to comment.