草庐IT

Named类型

全部标签

javascript - React Prop 类型与 Typescript

如果我在我的项目中使用typescript,那么React中prop-types的使用会过时吗?使用prop-types我将不得不经历定义类型的繁琐工作,但使用typescript,这一步将被取消。我的想法正确吗? 最佳答案 听起来不错。当您使用TypeScript时,您可以通过接口(interface)定义Prop。interfaceButtonProps{text:string,shadow?:boolean}constButton:React.FunctionComponent=props=>{return(/*[...]*/

javascript - 如何测试 Google 电子表格脚本中范围参数的类型?

我刚开始修改Google电子表格的脚本,但遇到了一个问题:如何判断函数参数的类型是否为单元格区域?我想做这样的事情:if(typeofintput!="range"){throw"inputmustbearange";}来自谷歌的例子here(页面中间):if(typeofinNum!="number"){//checktomakesureinputisanumberthrow"inputmustbeanumber";//throwanexceptionwiththeerrormessage}所以这似乎是测试变量类型的正确方法。但我不知道如何测试该类型是否是一系列单元格。如果我能指定范

javascript - Facebook Javascript SDK 未捕获类型错误 : Cannot read property 'userID' of undefined

我正在尝试使用FacebookJavaScriptSDK实现授权功能。当我运行它并检查控制台时,我看到了错误。uncaughtTypeError:Cannotreadproperty'userID'ofundefined代码片段varappId='APP_ID';varuid;//InitializetheJSSDKFB.init({appId:'413026618765431',cookie:true,});//Gettheuser'sUIDFB.getLoginStatus(function(response){uid=response.authResponse.userID?re

javascript - 类型错误 : Cannot read property 'latlng' of undefined

我正在尝试获取鼠标移动时的x,y坐标。我在尝试获取它时遇到错误。TypeError:Cannotreadproperty'latlng'ofundefinedatmouseMove(dashboard:593)atHTMLDivElement.onmousemove(dashboard:442)variMaxZoom=1;varmap=L.map('map',{crs:L.CRS.Simple,minZoom:-5,maxZoom:1});varbounds=[[0,0],[711,473]];varimage=L.imageOverlay('{!!asset('assets/imag

javascript - TypeScript:如何在编译时声明固定大小的数组以进行类型检查

更新:这些检查适用于编译时,而不是运行时。在我的例子中,失败的案例都在编译时被捕获,我期望其他应该失败的案例有类似的行为。假设我正在编写一个类似表的类,我希望该类的所有成员都是相同长度的数组,例如:classMyClass{tableHead:string[3];//expecttobea3elementarrayofstringstableCells:number[3];//expecttobea3elementarrayofnumbers}目前我找到的最接近的解决方案是:classMyClass{tableHead:[string,string,string];tableCells

javascript - 未捕获的类型错误 : Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined

我明白了UncaughtTypeErroroccurs(UncaughtTypeError:Cannotreadproperty'__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED'ofundefined)当我使用ReactJS时 最佳答案 抛出错误是因为react-dom找不到React的实例。我想这与您使用res/build/react-min.js而不是res/build/react.min.jsreact-dom中函数名称的荣誉:(function(React){returnReact.

javascript - Typescript 和 jQuery 类型。导入 jquery 类型的正确方法?

是否可以包含jquery.d.ts并使用jQueryStatic类型?我需要类似的东西...protectedel:jQueryStatic;...无论我如何尝试,我都无法从https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/jquery导入jQueryStatic接口(interface)非常感谢。更新///errorTS2304:Cannotfindname'jQuery'.///import{jQuery}from'jquery';errorTS2305:Module'"jquery"'hasnoexpor

javascript - 未捕获的类型错误 : lang is not a function

这个问题在这里已经有了答案:JSfunctionnamed`animate`doesn'tworkinChrome,butworksinIE(3个答案)关闭6年前。在我的HTML中,我在script标签中定义了lang函数并添加了“TestFire!”单击时必须调用lang的按钮:TestingFunctionsfunctionlang(){alert("Hello,World!It'sJavaScriptthistime");}但是,如果我点击按钮,我会得到这个错误:UncaughtTypeError:langisnotafunction但是,如果我将函数名称从lang更改为任何其他

javascript - 类型错误 : scrollIntoView is not a function

我是react-testing-library/jest的新手,正在尝试编写测试以查看路由导航(使用react-router-dom)是否正确执行。到目前为止,我一直在关注README还有这个tutorial关于如何使用。我的一个组件在本地函数中使用了scrollIntoView,这导致测试失败。TypeError:this.messagesEnd.scrollIntoViewisnotafunction45|46|scrollToBottom=()=>{>47|this.messagesEnd.scrollIntoView({behavior:"smooth"});|^48|}49|

javascript - TypeError [ERR_INVALID_ARG_TYPE] : The "original" argument must be of type Function. 接收类型未定义

在下面的代码中,我得到了这个错误:TypeError[ERR_INVALID_ARG_TYPE]:The"original"argumentmustbeoftypeFunction.Receivedtypeundefinedconstsqlite3=require('sqlite3').verbose();constutil=require('util');asyncfunctiongetDB(){returnnewPromise(function(resolve,reject){letdb=newsqlite3.Database('./project.db',(err)=>{if(e