TypeScript:如何导入ES6 JavaScript类?(TypeScript: How to import an ES6 JavaScript class?)
我有一个名为DB的ES6 JavaScript类定义如下:
// db.js "use strict"; export default class DB { ... }
和一个类似于以下内容的TypeScript文件:
// surgeons.ts "use strict"; import DB from "./db";
我希望这只是工作,但我得到以下错误:
Browserify Error { [TypeScript error: app/source/common/surgeons.ts(3,16): Error TS2307: Cannot find module './db'.] message: 'app/source/common/surgeons.ts(3,16): Error TS2307: Cannot find module \'./db\'.', fileName: 'app/source/common/surgeons.ts', line: 3, column: 16, name: 'TypeScript error' }
我试图定义一个db.d.ts文件,如此处所述,但这会产生错误:
Browserify Error { [TypeScript error: app/source/common/surgeons.ts(5,16): Error TS2306: File 'app/source/common/db.d.ts' is not a module.] message: 'app/source/common/surgeons.ts(5,16): Error TS2306: File \'app/source/common/db.d.ts\' is not a module.', fileName: 'app/source/common/surgeons.ts', line: 5, column: 16, name: 'TypeScript error' }
我的tsconfig如下:
{ "compilerOptions": { "module": "es6", "target": "es6", "moduleResolution": "node", "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, "allowSyntheticDefaultImports": true, "sourceMap": true }, "include": [ "app/source/**/*", "test/**/*" ], "exclude": [ "node_modules" ] }
I have an ES6 JavaScript class named DB defined as follows:
// db.js "use strict"; export default class DB { ... }
And a TypeScript file that looks like the following:
// surgeons.ts "use strict"; import DB from "./db";
I expect this to just work but I get the following error:
Browserify Error { [TypeScript error: app/source/common/surgeons.ts(3,16): Error TS2307: Cannot find module './db'.] message: 'app/source/common/surgeons.ts(3,16): Error TS2307: Cannot find module \'./db\'.', fileName: 'app/source/common/surgeons.ts', line: 3, column: 16, name: 'TypeScript error' }
I tried to define a db.d.ts file as described here but this generated the error:
Browserify Error { [TypeScript error: app/source/common/surgeons.ts(5,16): Error TS2306: File 'app/source/common/db.d.ts' is not a module.] message: 'app/source/common/surgeons.ts(5,16): Error TS2306: File \'app/source/common/db.d.ts\' is not a module.', fileName: 'app/source/common/surgeons.ts', line: 5, column: 16, name: 'TypeScript error' }
My tsconfig is as follows:
{ "compilerOptions": { "module": "es6", "target": "es6", "moduleResolution": "node", "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, "allowSyntheticDefaultImports": true, "sourceMap": true }, "include": [ "app/source/**/*", "test/**/*" ], "exclude": [ "node_modules" ] }
原文:https://stackoverflow.com/questions/44830647
更新时间:2023-11-23 22:11
最满意答案
# Example usage: # perl script.pl data.xml RootTag > RootTag.xml use strict; use warnings; my $tag = pop; while (<>){ if ( s/.*(<$tag>)/$1/ .. s/(<(\/)$tag>).*/$1/ ){ print; last if $2; } }
有关触发器操作符的详细信息,请参阅文档。
# Example usage: # perl script.pl data.xml RootTag > RootTag.xml use strict; use warnings; my $tag = pop; while (<>){ if ( s/.*(<$tag>)/$1/ .. s/(<(\/)$tag>).*/$1/ ){ print; last if $2; } }
See the docs for details on the flip-flop operator.
相关问答
更多-
你真的只需要使用那些工具吗? 它们不是为XML处理而设计的,虽然大多数情况下可以得到可行的结果,但它在编码,换行符等边缘情况下会失败。 我推荐xml_grep: xml_grep 'job' jobs.xml --text_only 这给出了输出: programming 在ubuntu / debian上,xml_grep位于xml-twig-tools软件包中。 Do you really have to use only those tools? They're not designed for ...
-
如何从linux中的多个xml文件中提取多个标记值(How to extract multiple tag values from multiple xml files in linux)[2022-01-11]
试试这个 - (创建两个示例文件f1.txt f2.txt) $ head f?.txt ==> f1.txt <==432361 Stuart 0251115 2016-11-14T22:27:53.477+08:00 682082 @ECHO OFF SETLOCAL SET "sourcedir=U:\sourcedir" SET "filename1=%sourcedir%\q40441783.txt" :: occurrence count for KEYWORD_1,KEYWORD_2,KEYWORD_3 FOR %%k IN (KEYWORD_1 KEYWORD_2 KEYWORD_3) DO ( FOR /f "delims=" %%c IN ('type "%filename1%"^|FIND /c "%%k"') D ...从xml中提取值(extract values from xml)[2024-03-03]
将XML与正则表达式匹配变得太复杂,太快。 你真的不应该这样做 。 使用XML解析器,Python有几个可供选择: ElementTree是标准库的一部分 lxml是一个快速且功能丰富的基于C的库。 ElementTree示例: from xml.etree import ElementTree tree = ElementTree.parse('filename.xml') for elem in tree.findall('lex'): print elem.attrib['marker'] ...更新:这是使用Sed的便携式简化方法: #!/bin/sed -nf # Execute the following group of commands for each line in the XML node to # generate a series of shell commands that we'll feed into an interpreter: //,/<\/xml>/ { # Extract the ID number to generate a command ... sed 's/.*\(.*\)<\/sending>.*/\1/' input.out>output.xml 你忘记删除该行的周围部分( .* ),sed只能获取你的模式的内容,并且在你的发送区块之前或之后你不包括char 现在我建议 sed -e '/.* \(.*\)<\/sending>.*/!d' -e 's//\1/' input.out>output.xml 它删除没有发送集团的线路。 不要忘记,sed的可用时间最长,所以如果在同一行(或更多)有两个区块,它 ... 添加到lwburk的解决方案中,要将DOM节点转换为字符串形式,可以使用Transformer : private static String nodeToString(Node node) throws TransformerException { StringWriter buf = new StringWriter(); Transformer xform = TransformerFactory.newInstance().newTransformer(); xform.se ...我把你的文档加载到了exist-db然后执行你的查询,本质上是这样的: xquery version "3.0"; let $medline := '/db/Medline/Data' let $doc := 'medline17n0001.xml' let $PMID := request:get-parameter("PMID", "") let $article := doc(concat($medline,'/',$doc))/PubmedArticleSet/PubmedArticle[Medli ...# Example usage: # perl script.pl data.xml RootTag > RootTag.xml use strict; use warnings; my $tag = pop; while (<>){ if ( s/.*(<$tag>)/$1/ .. s/(<(\/)$tag>).*/$1/ ){ print; last if $2; } } 有关触发器操作符的详细信息,请参阅文档。 # Example usage: ...从日志文件中提取日期(Extract date from log file)[2022-07-23]
由于路径中的格式为/.../YYYY/MM/DD/HH/MM/filename ,您可以在grep表达式中使用201D/DD/DD/DD/DD来匹配日期块: $ log="Tue Dec 9 10:48:13 2014 1 10.0.0.1 80 /home/DATA1/2014/12/11/16/20/blablabla_data2_11_16_20.txt b _ i r spy ftp 0 * c" $ echo "$log" | grep -oP '(?相关文章
更多- javascript 问题
- (二)solr data import
- javascript 注释
- javascript 基本语法
- Solr4.0(SolrCloud) & ElasticSearch(ES) 比较(二)
- Solr集群架构概述及delta-import详细配置
- Solr集群架构概述及delta-import详细配置
- javascript常用对象
- 解析JavaScript的事件机制
- 自己封装的一个Solr Data Import Request Handler Scheduler
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)