patch 8.2.1459: Vim9: declaring script var in script does not infer the type

Problem:    Vim9: declaring ascript variable at the script level does not
            infer the type.
Solution:   Get the type from the value. (closes #6716)
diff --git a/src/evalvars.c b/src/evalvars.c
index 43c05fd..d948dde 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -3049,7 +3049,10 @@
 						      + si->sn_var_vals.ga_len;
 		sv->sv_name = di->di_key;
 		sv->sv_tv = &di->di_tv;
-		sv->sv_type = type == NULL ? &t_any : type;
+		if (type == NULL)
+		    sv->sv_type = typval2type(tv, &si->sn_type_list);
+		else
+		    sv->sv_type = type;
 		sv->sv_const = (flags & LET_IS_CONST);
 		sv->sv_export = is_export;
 		++si->sn_var_vals.ga_len;