2017-08-02 64 views
0

角版本4.3.2发现角4“出口 'AnimationEvent' 不是在 '@角/动画'

@角/ CLI版本1.2.6

我使用的打字稿(V2.4.2 )对于进口

import {animate, AnimationEvent, state, style, transition, trigger} from '@angular/animations'; 

我收到说

“出口‘AnimationEvent’未发现在'@角/动画的警告组件

其他功能(动画,状态,样式等)不触发警告。我发现,在node_modules/@angular/animations.d.ts的@angular代码包括

export * from './public_api'; 

和./public_api.d.ts具有

export * from './src/animations'; 

和./src/animations.d .TS具有

export { AnimationBuilder, AnimationFactory } from './animation_builder'; 
export { AnimationEvent } from './animation_event'; 
export { AUTO_STYLE, AnimateChildOptions, AnimateTimings, AnimationAnimateChildMetadata, AnimationAnimateMetadata, AnimationAnimateRefMetadata, AnimationGroupMetadata, AnimationKeyframesSequenceMetadata, AnimationMetadata, AnimationMetadataType, AnimationOptions, AnimationQueryMetadata, AnimationQueryOptions, AnimationReferenceMetadata, AnimationSequenceMetadata, AnimationStaggerMetadata, AnimationStateMetadata, AnimationStyleMetadata, AnimationTransitionMetadata, AnimationTriggerMetadata, animate, animateChild, animation, group, keyframes, query, sequence, stagger, state, style, transition, trigger, useAnimation, ɵStyleData } from './animation_metadata'; 
export { AnimationPlayer, NoopAnimationPlayer } from './players/animation_player'; 
export * from './private_export'; 

和./animation_event.d.ts具有接口定义

export interface AnimationEvent { 
    fromState: string; 
    toState: string; 
    totalTime: number; 
    phaseName: string; 
    element: any; 
    triggerName: string; 
} 

如果我将接口定义复制到我的代码中,一切正常。

所有这些与我用过的许多其他导入非常相似,但是这是唯一一个会产生警告的导入。

如何在不将接口定义复制到我的代码中的情况下防止这些警告?

回答

1

app-module.ts:您是否导入BrowserAnimationsModule?

请参阅here的文档。

随着一只蹦床example

import { NgModule } from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 
@NgModule({ 
    imports: [ BrowserModule, BrowserAnimationsModule ], 
}) 

如果不解决这个问题:

  • 请记下什么system.config.js在Plunker在做什么。
  • 另一相关资源是github issues thread

请务必评论哪些步骤,如果有任何修复它。 ;-)

+0

我确实导入了BrowserAnimationsModule,并且所有的动画都按预期工作。事实上,除了编译器警告之外,一切正在运行并按预期工作。 –

+0

TL; DR通过将tsconfig.js compilerOptions.module从“es2015”更改为“CommonJS”来修复。假设这必须是编译器配置,我分析了Plunker中的systemjs.config.js,以与我的(Angular CLI生成的)tsconfig.app.json文件进行比较。只有两个区别,1)noImplicitAny:true,和2)module:'commonjs'。我改变了两个,一次一个。TypeScript文档声明模块类型是CommonJS,所以我使用了它。我希望这种改变不会导致其他问题... –

+0

https://www.typescriptlang.org/docs/handbook/compiler-options.html --noImplicitAny在表达式和声明上引发错误,隐含任何'类型。所以这可能没有必要。但很高兴你解决了它。 – JGFMK