Open lung21 opened 2 years ago
Hi @lung21,
Is this the case that there will be 2 type errors (type conflict) in the below code?
let obj: any = { content: 'heymycontent' };
obj = 23; // ==> assign an integer value to a record?
function isView(arg: any): boolean {
// Do something here
}
// the output of this function may be of any
function calculate(argA: string, argB: number): any {
return argA + argB; // ===> addition of a string and a number
}
@taquangtrung Thank you for responding.
In short, Typescript considers these not erroneous with any
unless we explicitly tell it not to allow any
, but unfortunately we will still encounter any
in other libraries even though we do not in our .ts source file.
I think for these two cases, we can do a simple type check and report errors if there are type conflicts.
If the type of one operand is a sub-type of the other, maybe we can instantiate any
by the super type?
Motivation
Similar to Javascript, Typescript also supports type
any
that allows a variable of that type to be assigned values of any other types. This also means that the type checking is disabled wheneverany
is used in Typescript. Now we are trying to find how any constructs withany
could be possibly translated into LLVM IR. Below is an example of one variable and two functions that are defined withany
in Typescript.Example