Typescript 4.5.5
NodeJS 14
This is my first ever question here. after a whole day i am at my wits end, cannot figure out what’s wrong, tried so many things then posted here.
- Property ‘video‘ does not exist on type ‘{}’.ts(2339) in data.video
- Property ‘title‘ does not exist on type ‘{}’.ts(2339) in data.title
- Property ‘desc‘ does not exist on type ‘{}’.ts(2339) in data.desc
you get the idea.
export default function Upload() {
const [title, setTitle] = useState<string>('')
const [description, setDescription] = useState<string>('')
const [category, setCategory] = useState<string>('')
const [location, setLocation] = useState<string>('')
const [thumbnail, setThumbnail] = useState<File>()
const [uploadData, setUploadData] = useState({})
const [video, setVideo] = useState<File>()
const thumbnailRef = useRef<HTMLInputElement>(null)
const { mutate: createAsset, data: asset, uploadProgress } = useCreateAsset()
const goBack = () => {
window.history.back()
}
// When a user clicks on the upload button
const handleSubmit = async () => {
// Calling the upload video function
await uploadVideo()
// Calling the upload thumbnail function and getting the CID
const thumbnailCID = await uploadThumbnail()
// Creating a object to store the metadata
let data = {
video: asset?.id,
title,
description,
location,
category,
thumbnail: thumbnailCID,
UploadedDate: Date.now(),
}
// Calling the saveVideo function and passing the metadata object
console.log(data)
await saveVideo(data)
}
// Function to upload the video to IPFS
const uploadThumbnail = async () => {
// Passing the file to the saveToIPFS function and getting the CID
const cid = await saveToIPFS(thumbnail)
// Returning the CID
return cid
}
// Function to upload the video to Livepeer
const uploadVideo = async () => {
// Calling the createAsset function from the useCreateAsset hook to upload the video
createAsset({
name: title,
file: video,
})
}
// Function to save the video to the Contract
const saveVideo = async (data = uploadData) => {
// Get the contract from the getContract function
let contract = await getContract()
// Upload the video to the contract
await contract.uploadVideo(
data.**video**,
data.**title**,
data.**description**,
data.**location**,
data.**category**,
data.**thumbnail**,
false,
data.**UploadedDate**
)
}
This is the schema.ts of graphprotocol. it was automatically generated but its getting errors when npm run build
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import {
TypedMap,
Entity,
Value,
ValueKind,
store,
Bytes,
BigInt,
BigDecimal
} from "@graphprotocol/graph-ts";
export class Video extends Entity {
constructor(id: string) {
super();
this.set("id", Value.fromString(id));
}
save(): void {
let id = this.get("id");
assert(id != null, "Cannot save Video entity without an ID");
if (id) {
**assert**(
id.kind == ValueKind.STRING,
`Entities of type Video must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}`
);
store.set("Video", id.toString(), this);
}
}
static load(id: string): Video | null {
return **changetype**<Video | null>(store.get("Video", id));
Type error: Cannot find name 'assert'.
20 | save(): void {
21 | let id = this.get("id");
> 22 | assert(id != null, "Cannot save Video entity without an ID");
| ^
23 | if (id) {
24 | assert(
25 | id.kind == ValueKind.STRING,
Type error: Cannot find name 'changetype'.
32 |
33 | static load(id: string): Video | null {
> 34 | return changetype<Video | null>(store.get("Video", id));
| ^
35 | }
36 |
37 | get id(): string {
This is my tsconfig.ts file
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"typeRoots": [
"../node_modules/@types"
],
"types" : [
"core-js","node"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"incremental": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"baseUrl": ".",
"paths": {
"@components/*" : ["./components/*"],
"@pages/*" : ["./pages/*"],
"@styles/*" : ["./styles/*"],
"@utils/*" : ["./utils/*"],
"@public/*" : ["./public/*"],
"@assets/*" : ["./assets/*"],
"@types/*" : ["./types/*"],
"@clients/*" : ["./clients/*"],
"@constants/*" : ["./constants/*"],
"@layouts/*" : ["./layouts/*"],
"@queries/*" : ["./queries/*"],
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"components",
"./*",
"@components/*",
"@pages/**/*",
"@src/**/*",
"next.config.js",
"public"
],
"exclude": [
"node_modules",
"typings/browser.d.ts",
"typings/browser",
]
}
Packages.json
{
"name": "Decentralized-YouTube",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@apollo/client": "^3.6.9",
"@babel/core": "^7.0.0",
"@livepeer/react": "^0.4.0",
"@nomicfoundation/hardhat-chai-matchers": "^1.0.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^3.0.0",
"@rainbow-me/rainbowkit": "^0.6.0",
"@typechain/ethers-v5": "^10.1.0",
"@typechain/hardhat": "^6.1.2",
"@types/chai": "^4.2.0",
"@types/mocha": "^9.1.0",
"avvvatars-react": "^0.4.2",
"axios": "^0.27.2",
"chai": "^4.2.0",
"dotenv": "^16.0.2",
"ethers": "^5.7.1",
"graphql": "^16.6.0",
"hardhat-gas-reporter": "^1.0.8",
"ipfs-http-client": "^58.0.0",
"livepeer": "^0.4.0",
"moment": "^2.29.4",
"next": "12.3.0",
"plyr-react": "^5.1.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hot-toast": "^2.4.0",
"react-icons": "^4.4.0",
"solidity-coverage": "^0.8.1",
"ts-node": ">=8.0.0",
"typechain": "^8.1.0",
"wagmi": "^0.6.6",
"web3.storage": "^4.4.0",
"typescript": "^4.5.5"
},
"devDependencies": {
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
"@types/core-js": "^2.5.5",
"@types/node": "^18.15.0",
"@types/react": "18.0.20",
"autoprefixer": "^10.4.11",
"eslint": "8.23.1",
"eslint-config-next": "12.3.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-import": "^2.26.0",
"hardhat": "^2.11.2",
"postcss": "^8.4.16",
"tailwindcss": "^3.1.8",
}
}
Tried upgrading, downgrading packages , declare var assert:any and var changetype:any but then it says on changetypes’s turn :
Type error: Untyped function calls may not accept type arguments.
first on ubuntu then on windows but in vain
tried different suggestions from stackoverflow of adding lines to eslintrc and tsconfig.json file