当我尝试将本地JavaScript文件的链接引用更改为GitHub原始版本时,我的测试文件停止工作.错误是:
拒绝从...执行脚本,因为它的MIME类型(
text/plain)不可执行,并且启用了严格的MIME类型检查.
有没有办法禁用此行为或是否有允许链接到GitHub原始文件的服务?
工作代码:
<script src="bootstrap-wysiwyg.js"></script>
Run Code Online (Sandbox Code Playgroud)
非工作代码:
<script src="https://raw.github.com/mindmup/bootstrap-wysiwyg/master/bootstrap-wysiwyg.js"></script>
Run Code Online (Sandbox Code Playgroud) 谁能解释为什么第二个变体不起作用?这是一个错误吗?
const prints = (s: string): void => console.log(s);
var x: string | number = Date.now() % 2 ? "test" : 5;
// 1st: working
if (typeof x === "string") {
prints(x);
}
// 2nd: not working
var typex = typeof x === "string";
if (typex) {
prints(x);
}
Run Code Online (Sandbox Code Playgroud)
第二个变体显示以下错误:
'string | 类型的参数 number' 不能分配给类型为 'string' 的参数。“数字”类型不能分配给“字符串”类型
我有一些可清除的选择,我想将applets状态字段重置为空数组。
const defaultFormValues = { device: { ...initialDevice }, applets: [] };
const { control, getValues, setValue, reset, handleSubmit } = useForm<CreateDeviceFormData>({
mode: "all",
reValidateMode: "onChange",
defaultValues: defaultFormValues,
resolver: yupResolver(validationSchema),
});
const onChangeHandler = React.useCallback(
(value: Experience | null) => {
if (value) {
setValue("applets", getApplets(value));
} else {
setValue("applets", []);
// reset(defaultFormValues);
}
setValue("device.experience_id", value ? value.id : undefined);
},
[templateSelector, setValue],
);
console.log("current data", getValues(), control);
return (
<>
<SomeAutocompleteComponent control={control} onChange={onChangeHandler} />
<SelectAppletsComponent control={control} /> …Run Code Online (Sandbox Code Playgroud) javascript ×3
frontend ×1
github ×1
react-hooks ×1
reactjs ×1
string ×1
typeof ×1
typescript ×1