【问题标题】:typescript 1.3 sometimes giving false type mis-match errorstypescript 1.3 有时会给出错误的类型不匹配错误
【发布时间】:2014-11-17 18:44:35
【问题描述】:

当我使用运行 tsc 的 WebStorm 文件观察器进行编译时,有时会得到以下信息:

../paragraph/paragraph.ts(193,29): error TS2345: Argument of type 'TYPE' is not assignable to parameter of type 'TYPE'.
../paragraph/paragraph.ts(255,75): error TS2345: Argument of type 'Paragraph' is not assignable to parameter of type 'Paragraph'.
../paragraph/tab.ts(241,37): error TS2345: Argument of type 'ArrayList<TabAttributes>' is not assignable to parameter of type 'ArrayList<TabAttributes>'.
  Type 'TabAttributes' is not assignable to type 'TabAttributes'.

我收到了大约 20 个。当我使用 VS2013 编译时,没有问题。当我运行代码时,没有问题。但是编译器似乎对这些东西感到窒息。这只是在我们升级到 typescript 1.3 时才开始发生的。

澄清:当我全部使用 VisualStudio 进行构建时,我没有收到来自 typescript 编译的错误或警告。当 WebStorm 编译时,我有时会得到它。但 WebStorm 只是将编译器输出传回显示器。

发生了什么事?

更新 - 这是在 DOS 框中编译的输出:

C:\src\jenova\Dev\Merge\AutoTagWeb\client\scripts\layout\document\elements\parag
raph>tsc --target ES5 --module amd --sourcemap paragraph.ts
../../../document/elements/paragraph/line.ts(127,41): error TS2339: Property 'LI
NE' does not exist on type 'typeof TYPE'.
../../../document/elements/position.ts(75,40): error TS2339: Property 'POSITION'
 does not exist on type 'typeof TYPE'.
../../../document/elements/position.ts(184,59): error TS2339: Property 'ABSOLUTE
_POSITION' does not exist on type 'typeof TYPE'.
../../../document/elements/position.ts(193,40): error TS2339: Property 'ABSOLUTE
_POSITION' does not exist on type 'typeof TYPE'.
../../../document/elements/run/run.ts(57,40): error TS2339: Property 'RUN_ELEMEN
T' does not exist on type 'typeof TYPE'.
../../../document/list-body.ts(537,41): error TS2339: Property 'LINE' does not e
xist on type 'typeof TYPE'.
../../../final-format.ts(719,62): error TS2339: Property 'LINE' does not exist o
n type 'typeof TYPE'.
../../../handlers/para-handler.ts(510,52): error TS2339: Property 'RUN_ELEMENT'
does not exist on type 'typeof TYPE'.
../../../handlers/para-handler.ts(522,51): error TS2339: Property 'BLOCK' does n
ot exist on type 'typeof TYPE'.
../../../handlers/para-handler.ts(565,52): error TS2339: Property 'RUN_ELEMENT'
does not exist on type 'typeof TYPE'.
../../../handlers/para-handler.ts(570,52): error TS2339: Property 'BLOCK' does n
ot exist on type 'typeof TYPE'.
../../../handlers/text-handler.ts(63,42): error TS2339: Property 'RUN_ELEMENT' d
oes not exist on type 'typeof TYPE'.
../../../handlers/text-handler.ts(99,42): error TS2339: Property 'LINE' does not
 exist on type 'typeof TYPE'.
../../../handlers/text-handler.ts(108,41): error TS2339: Property 'BLOCK' does n
ot exist on type 'typeof TYPE'.
../../../handlers/text-handler.ts(561,39): error TS2339: Property 'POSITION' doe
s not exist on type 'typeof TYPE'.
../../../handlers/text-handler.ts(571,39): error TS2339: Property 'LINE' does no
t exist on type 'typeof TYPE'.
../../elements/paragraph/line.ts(127,41): error TS2339: Property 'LINE' does not
 exist on type 'typeof TYPE'.
../../elements/position.ts(75,40): error TS2339: Property 'POSITION' does not ex
ist on type 'typeof TYPE'.
../../elements/position.ts(184,59): error TS2339: Property 'ABSOLUTE_POSITION' d
oes not exist on type 'typeof TYPE'.
../../elements/position.ts(193,40): error TS2339: Property 'ABSOLUTE_POSITION' d
oes not exist on type 'typeof TYPE'.
../../elements/run/run.ts(57,40): error TS2339: Property 'RUN_ELEMENT' does not
exist on type 'typeof TYPE'.
../../list-body.ts(537,41): error TS2339: Property 'LINE' does not exist on type
 'typeof TYPE'.
../paragraph/line.ts(127,41): error TS2339: Property 'LINE' does not exist on ty
pe 'typeof TYPE'.
../paragraph/paragraph-properties.ts(429,14): error TS2421: Class 'ParagraphProp
ertyValues' incorrectly implements interface 'IParagraphPropertyValues':
  Types of property 'parent' are incompatible:
    Type 'Paragraph' is not assignable to type 'IParagraph':
      Types of property 'type' are incompatible:
        Type 'TYPE' is not assignable to type 'TYPE'.
../paragraph/paragraph.ts(94,14): error TS2416: Class 'Paragraph' incorrectly ex
tends base class 'Line':
  Types of property 'isType' are incompatible:
    Type '(type: TYPE) => boolean' is not assignable to type '(type: TYPE) => bo
olean':
      Types of parameters 'type' and 'type' are incompatible:
        Type 'TYPE' is not assignable to type 'TYPE'.
../paragraph/paragraph.ts(94,14): error TS2421: Class 'Paragraph' incorrectly im
plements interface 'IParagraph':
  Types of property 'props' are incompatible:
    Type 'ParagraphPropertyValues' is not assignable to type 'IParagraphProperty
Values'.
../paragraph/paragraph.ts(193,29): error TS2345: Argument of type 'TYPE' is not
assignable to parameter of type 'TYPE'.
../paragraph/paragraph.ts(230,13): error TS2323: Type 'Paragraph' is not assigna
ble to type 'IParagraph'.
../paragraph/paragraph.ts(248,34): error TS2353: Neither type 'IParagraphPropert
yValues' nor type 'ParagraphPropertyValues' is assignable to the other:
  Property 'className' is missing in type 'IParagraphPropertyValues'.
../paragraph/paragraph.ts(255,75): error TS2345: Argument of type 'Paragraph' is
 not assignable to parameter of type 'Paragraph'.
../paragraph/paragraph.ts(274,22): error TS2345: Argument of type 'Paragraph' is
 not assignable to parameter of type 'Line'.
../paragraph/paragraph.ts(306,30): error TS2345: Argument of type 'Paragraph' is
 not assignable to parameter of type 'IParagraph'.
../paragraph/paragraph.ts(385,13): error TS2365: Operator '!==' cannot be applie
d to types 'SUFFIX' and 'SUFFIX'.
../paragraph/paragraph.ts(386,17): error TS2365: Operator '===' cannot be applie
d to types 'SUFFIX' and 'SUFFIX'.
../paragraph/paragraph.ts(562,41): error TS2345: Argument of type 'Paragraph' is
 not assignable to parameter of type 'Line'.
../paragraph/paragraph.ts(602,28): error TS2353: Neither type 'Element' nor type
 'RunProperties' is assignable to the other:
  Types of property 'type' are incompatible:
    Type 'TYPE' is not assignable to type 'TYPE'.
../paragraph/paragraph.ts(619,36): error TS2345: Argument of type 'RunProperties
' is not assignable to parameter of type 'Element[]'.
../paragraph/paragraph.ts(622,51): error TS2345: Argument of type 'RunProperties
' is not assignable to parameter of type 'Element[]'.
../paragraph/paragraph.ts(636,15): error TS2353: Neither type 'Element' nor type
 'RunPropertyValues' is assignable to the other:
  Property 'parent' is missing in type 'Element'.
../paragraph/paragraph.ts(695,16): error TS2353: Neither type 'Element' nor type
 'Paragraph' is assignable to the other:
  Property 'docHeader' is missing in type 'Element'.
../paragraph/tab.ts(241,37): error TS2345: Argument of type 'ArrayList<TabAttrib
utes>' is not assignable to parameter of type 'ArrayList<TabAttributes>'.
  Type 'TabAttributes' is not assignable to type 'TabAttributes'.
../paragraph/tab.ts(295,60): error TS2345: Argument of type 'ArrayList<TabAttrib
utes>' is not assignable to parameter of type 'ArrayList<TabAttributes>'.
  Type 'TabAttributes' is not assignable to type 'TabAttributes'.
../position.ts(75,40): error TS2339: Property 'POSITION' does not exist on type
'typeof TYPE'.
../position.ts(184,59): error TS2339: Property 'ABSOLUTE_POSITION' does not exis
t on type 'typeof TYPE'.
../position.ts(193,40): error TS2339: Property 'ABSOLUTE_POSITION' does not exis
t on type 'typeof TYPE'.
../run/run-properties.ts(729,46): error TS2345: Argument of type 'REGION' is not
 assignable to parameter of type 'REGION'.
../run/run.ts(57,40): error TS2339: Property 'RUN_ELEMENT' does not exist on typ
e 'typeof TYPE'.
../section.ts(395,59): error TS2345: Argument of type 'Section' is not assignabl
e to parameter of type 'Section'.
../section.ts(792,67): error TS2345: Argument of type 'Section' is not assignabl
e to parameter of type 'Section'.
../table/table.ts(133,16): error TS2353: Neither type 'Element' nor type 'Row' i
s assignable to the other:
  Property 'props' is missing in type 'Element'.
line.ts(127,41): error TS2339: Property 'LINE' does not exist on type 'typeof TY
PE'.
paragraph-properties.ts(429,14): error TS2421: Class 'ParagraphPropertyValues' i
ncorrectly implements interface 'IParagraphPropertyValues':
  Types of property 'parent' are incompatible:
    Type 'Paragraph' is not assignable to type 'IParagraph':
      Types of property 'type' are incompatible:
        Type 'TYPE' is not assignable to type 'TYPE'.
paragraph.ts(94,14): error TS2416: Class 'Paragraph' incorrectly extends base cl
ass 'Line':
  Types of property 'isType' are incompatible:
    Type '(type: TYPE) => boolean' is not assignable to type '(type: TYPE) => bo
olean':
      Types of parameters 'type' and 'type' are incompatible:
        Type 'TYPE' is not assignable to type 'TYPE'.
paragraph.ts(94,14): error TS2421: Class 'Paragraph' incorrectly implements inte
rface 'IParagraph':
  Types of property 'props' are incompatible:
    Type 'ParagraphPropertyValues' is not assignable to type 'IParagraphProperty
Values'.
paragraph.ts(193,29): error TS2345: Argument of type 'TYPE' is not assignable to
 parameter of type 'TYPE'.
paragraph.ts(230,13): error TS2323: Type 'Paragraph' is not assignable to type '
IParagraph'.
paragraph.ts(248,34): error TS2353: Neither type 'IParagraphPropertyValues' nor
type 'ParagraphPropertyValues' is assignable to the other:
  Property 'className' is missing in type 'IParagraphPropertyValues'.
paragraph.ts(255,75): error TS2345: Argument of type 'Paragraph' is not assignab
le to parameter of type 'Paragraph'.
paragraph.ts(274,22): error TS2345: Argument of type 'Paragraph' is not assignab
le to parameter of type 'Line'.
paragraph.ts(306,30): error TS2345: Argument of type 'Paragraph' is not assignab
le to parameter of type 'IParagraph'.
paragraph.ts(385,13): error TS2365: Operator '!==' cannot be applied to types 'S
UFFIX' and 'SUFFIX'.
paragraph.ts(386,17): error TS2365: Operator '===' cannot be applied to types 'S
UFFIX' and 'SUFFIX'.
paragraph.ts(562,41): error TS2345: Argument of type 'Paragraph' is not assignab
le to parameter of type 'Line'.
paragraph.ts(602,28): error TS2352: Neither type 'Element' nor type 'RunProperti
es' is assignable to the other.
paragraph.ts(619,36): error TS2345: Argument of type 'RunProperties' is not assi
gnable to parameter of type 'Element[]'.
paragraph.ts(622,51): error TS2345: Argument of type 'RunProperties' is not assi
gnable to parameter of type 'Element[]'.
paragraph.ts(636,15): error TS2352: Neither type 'Element' nor type 'RunProperty
Values' is assignable to the other.
paragraph.ts(695,16): error TS2353: Neither type 'Element' nor type 'Paragraph'
is assignable to the other:
  Property 'docHeader' is missing in type 'Element'.
tab.ts(241,37): error TS2345: Argument of type 'ArrayList<TabAttributes>' is not
 assignable to parameter of type 'ArrayList<TabAttributes>'.
  Type 'TabAttributes' is not assignable to type 'TabAttributes'.
tab.ts(295,60): error TS2345: Argument of type 'ArrayList<TabAttributes>' is not
 assignable to parameter of type 'ArrayList<TabAttributes>'.
  Type 'TabAttributes' is not assignable to type 'TabAttributes'.

【问题讨论】:

  • 澄清一下,如果您通过 Visual Studio 运行 TS 1.3 编译器,它不会给出该消息,只有当您从 webstorm 运行它时?还是您的意思是当您将文件保存在 Visual Studio 中时,它仍然会正确创建 js 文件但会出错?
  • @John - 更新了 Q 以澄清。
  • 你能在命令行编译器(tsc.exe 或 tsc.js)中重现这些错误吗?
  • @RyanCavanaugh - 是的,在命令行它有很多错误。我会在上面发帖。从我们从 1.1 切换到 1.3 时,这个文件没有改变。而且它之前编译得很好。
  • 你能把有这个错误的代码行贴出来吗,可能把它简化为一个更简单的例子

标签: typescript webstorm


【解决方案1】:

当我更新到 1.3 时,我遇到了完全相同的问题,经过一段时间的挖掘,我找到了答案。

1.3 版的编译器显然不喜欢相对路径,因此您必须对所有编译器参数仅使用绝对路径。

对我来说特别的问题是 TypeScript 文件观察程序参数中的 $FileName$(相对路径)宏。
将其更改为 $FilePath$(绝对路径)修复它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    相关资源
    最近更新 更多