any
type JS-0323 1/* eslint-disable no-console */
2
3import Web3 from "web3";
4declare var window: any 5
6const getWeb3 = async () => {
7 // Wait for loading completion to avoid race conditions with web3 injection timing.
144 </button>
145 </div>
146 <div className="max-h-[600px] overflow-y-auto">
147 {tasks?.map((task: any, i: number) => (148 <div key={i} className="form-control border-b-2">
149 <label className="cursor-pointer label">
150 <span
12
13const Home = () => {
14 const [account, setAccount] = useState<string>();
15 const [tasks, setTasks] = useState<any>([]); 16 const [todoList, setTodoList] = useState<TodoList>();
17 const [message, setMessage] = useState("");
18 const [loading, setLoading] = useState(true);
The any
type can sometimes leak into your codebase. TypeScript compiler skips the type checking of the any
typed variables, so it creates a potential safety hole, and source of bugs in your codebase. We recommend using unknown
or never
type variable.
In TypeScript, every type is assignable to any
. This makes any
a top type (also known as a universal supertype) of the type system.
The any
type is essentially an escape hatch from the type system. As developers, this gives us a ton of freedom: TypeScript lets us perform any operation we want on values of type any
without having to perform any checking beforehand.
The developers should not assign any
typed value to variables and properties, which can be hard to pick up on, especially from the external library; instead, developers can use the never
or unknown
type variable.
const age: any = 'seventeen';
const ages: any[] = ['seventeen'];
const ages: Array<any> = ['seventeen'];
function greet(): any {}
function greet(): any[] {}
function greet(): Array<any> {}
function greet(): Array<Array<any>> {}
function greet(param: Array<any>): string {}
function greet(param: Array<any>): Array<any> {}
const age: number = 17;
const ages: number[] = [17];
const ages: Array<number> = [17];
function greet(): string {}
function greet(): string[] {}
function greet(): Array<string> {}
function greet(): Array<Array<string>> {}
function greet(param: Array<string>): string {}
function greet(param: Array<string>): Array<string> {}