Can anyone help me with this

idl.ts:1562 Uncaught (in promise) Error: Invalid opt record {text; μrec_0.opt record {0:text; 1:rec_0}} argument: [“Rahul Aauji”]

→ Invalid record {text; μrec_0.opt record {0:text; 1:rec_0}} argument: “Rahul Aauji”

this the code
actor dblogs{
public type Post = {
Title:Text;
Image:Text;
Author:List.List;
Content:Text;
Date:Text;
};

var blogs:List.List = List.nil ();

public func createBlog(title:Text,image:Text,author:List.List,content:Text,date:Text){
let newBlog = {
Title = title;
Image = image;
Author = author;
Content = content;
Date = date;
};
blogs := List.push(newBlog,blogs);
Debug.print(debug_show(blogs))
}
}
i’ve connected to javascript react front end i and passed an array of author during this i got this error

1 Like

It’s hard to say exactly but i think the issue is you are using a List vs an array
Try changing your List.List arg to a [Text]

1 Like

thanks for your reply I’ve already done that idk why the arguments are not showing in this

1 Like

Hi @rahulaauji-30

public type Post = {
Title: Text;
Image: Text;
Author: List.List; // Assuming Author is a list of Texts. The generic type needs to be specified.
Content: Text;
Date: Text;
};

Incorrect List.List Usage

import List “mo:base/List”;

Use of List.push Function

blogs := List.cons(newBlog, blogs);

Try this:
import List “mo:base/List”;
import Debug “mo:base/Debug”;

actor dblogs {
public type Post = {
title: Text;
image: Text;
author: List.List; // Assuming Author is a list of Texts
content: Text;
date: Text;
};

var blogs: List.List = List.nil();

public func createBlog(title: Text, image: Text, author: List.List, content: Text, date: Text) {
let newBlog: Post = {
title = title,
image = image,
author = author,
content = content,
date = date
};
blogs := List.cons(newBlog, blogs);
Debug.print(Debug.debug_show(blogs));
}
}