首页 > 其他分享 >TypeScript 报错:Type '({ filename: string; createTime: string; filePath: string; fileId: number;

TypeScript 报错:Type '({ filename: string; createTime: string; filePath: string; fileId: number;

时间:2023-04-15 09:33:41浏览次数:33  
标签:assignable TypeScript const string 报错 Type name

问题:
因为TypeScript不支持直接给一个接口类型的变量 赋一个未知的值。

const a:A = {
	name:'s'
};

你需要给这样的对象数组值使用as 指定一个类型。

正确写法:

const a:A = {
	name:'s'
} as A;

数组写法一样:

const a:A[] = [
	{
		name:'s'
	}
] as A[];

使用 as 将一个值断言为 Type 类型。

标签:assignable,TypeScript,const,string,报错,Type,name
From: https://www.cnblogs.com/pphboy/p/17320527.html

相关文章

  • typescript vue3 VueDraggable 报错 Uncaught TypeError: Cannot read properties of
    UncaughtTypeError:Cannotreadpropertiesofnull(reading'element')nnotreadpropertiesofnull(reading'index')错误写法就是说子组件需要用div包着,你用其他东西,他无法添加key,然后就会报错。<template#item="{element}"><Todo:detail=......
  • UVA1650 数字串 Number String
    对于任意一个只含数字1~n的有序数字串{a1,a2,……,an},比较数字串中所有相邻数字的大小,后者大于前者的用I表示,否则用D表示。例如,数字串{3,1,2,7,4,6,5},{2,1,3,7,4,6,5}和{3,1,2,7,5,6,4}就表示为'DIIDID'。"?"则表示两数的关系未知。例如,'?D'既有可能是ID,也有可能是‘DD’。现给出......
  • Yunzai-BotQQ账号登录报错:token失效: [禁止登录]你当前使用的QQ版本过低,请前往QQ官网i
    token失效:[禁止登录]你当前使用的QQ版本过低解决方案写在前面:该问题是TX认为账号有被用作BOT的嫌疑,而阻止你登陆。但是由于是我们人类在登陆,用来卡BOT的验证码测试肯定可以通过,TX就用“版本过低”的问题来卡我们!!TX我***网上尝试了许多方法,包括对device.json大改特改,还说什么......
  • Maui安卓调试时部署报错:ADB1000
    突发情况,于是重新建了个项目,什么都没动的直接选择安卓仿真器。点击部署。于是等了半天,打开仿真器变慢了。部署也变慢了,CPU直接嗷嗷响,温度瞬间直飙80多度。接着仿真器是打开了,但一直都是黑屏。然后就是一个报错。报错内容: 错误ADB1000:System.IO.FileNotFoundException:......
  • R语言:Some 'from' names in value not found on 'x' 报错
    升级了dplyr后运行命令inter=inter%>%rename("gene"="V4")就一直报错:Some'from'namesinvaluenotfoundon'x',如下所示:Errorinrename(.,gene="V4"):Some'from'namesinvaluenotfoundon'x'......
  • Educational Codeforces Round 110 (Rated for Div. 2) C. Unstable String(状态机)
    https://codeforces.com/contest/1535/problem/C题目大意:给定一个字符串s,由10?组成:?每次都可以任意替换成0或者1问我们这个子字符串中,能够组成010101这样两两互不相等的字符串的数量最大是多少?input30?10????10??1100output8625#include<bits/stdc++.h>usin......
  • Pod Init Error: "force_encoding': can't modify frozen String (FrozenError)"
    热烈欢迎,请直接点击!!!进入博主AppStore主页,下载使用各个作品!!!注:博主将坚持每月上线一个新app!!!我发现使用Xcode14新创建的新项目有这个问题,可以按照图中操作切换为Xcode13,解决此问题。......
  • 2023-04-14 uni-popup 报错:Error in config.errorHandler: "RangeError: Maximum call
    问题描述:首次导入uniapp的uni-popup,在项目中使用时报错,业务场景为:页面渲染完成后显示弹窗。报错:Errorinconfig.errorHandler:"RangeError:Maximumcallstacksizeexceeded"config.errorHandler中的错误:“RangeError:超出了最大调用堆栈大小”页面如下:<uni-popupref="l......
  • C语言报错
    1、Useofundeclaredidentifier'SPIT_FLAG_TIMEOUT'  解决:使用未定义的标识符:SPIT_FLAG_TIMEOUT没有定义,但用#define修饰的语句又不标红。......
  • re.findall()用法详解-返回string中所有与pattern相匹配的全部字串
    re.findall():函数返回包含所有匹配项的列表。返回string中所有与pattern相匹配的全部字串,返回形式为数组。  示例代码1:【打印所有的匹配项】   importre       s="Longlivethepeople'sRepublicofChina"   ret=re.findall('h',s)       ......