Generics Dart:通用方法不起作用
我对泛型方法有问题。 举个例子,我用Angular2在WebStorm中生成了一个新项目。 我使用的是dart 1.22.0-DEV10.1,但我在dart 1.21.1中也遇到了问题。 我在app_component.dart文件中添加了一个类:Generics Dart:通用方法不起作用,generics,dart,dart-pub,Generics,Dart,Dart Pub,我对泛型方法有问题。 举个例子,我用Angular2在WebStorm中生成了一个新项目。 我使用的是dart 1.22.0-DEV10.1,但我在dart 1.21.1中也遇到了问题。 我在app_component.dart文件中添加了一个类: import 'package:angular2/core.dart'; import 'package:angular2_components/angular2_components.dart'; import 'package:deleteMe
import 'package:angular2/core.dart';
import 'package:angular2_components/angular2_components.dart';
import 'package:deleteMe/hello_dialog/hello_dialog.dart';
@Component(
selector: 'my-app',
styleUrls: const ['app_component.css'],
templateUrl: 'app_component.html',
directives: const [materialDirectives, HelloDialog],
providers: const [materialProviders],
)
class AppComponent {
// Nothing here yet. All logic is in HelloDialog.
}
class abc {
T foo<T>(T value) {
return value;
}
}
import'包:angular2/core.dart';
导入“包:angular2_组件/angular2_组件.dart”;
导入“package:deleteMe/hello_dialog/hello_dialog.dart”;
@组成部分(
选择器:“我的应用程序”,
styleURL:const['app_component.css'],
templateUrl:'app_component.html',
指令:常量[materialDirectives,HelloDialog],
提供者:常量[材料提供者],
)
类AppComponent{
//这里还没有,所有的逻辑都在HelloDialog里。
}
abc班{
T foo(T值){
返回值;
}
}
分析器不会抛出任何错误,但是,当我尝试运行该示例时,我从pub中得到以下错误:
[DirectiveProcessor]:
Failed with 4 errors
Error 1: line 23, column 5 of lib\app_component.dart and parts: Expected to find ';'
T foo<T>(T value) {
^^^
Error 2: line 23, column 8 of lib\app_component.dart and parts: Expected a class member
T foo<T>(T value) {
^
Error 3: line 23, column 8 of lib\app_component.dart and parts: Unexpected token '<'
T foo<T>(T value) {
^
Error 4: line 23, column 10 of lib\app_component.dart and parts: Operator declarations must be preceeded by the keyword 'operator'
T foo<T>(T value) {
^
Build error:
Transform DirectiveProcessor on deleteMe|lib/app_component.dart threw error: Error in lib/app_component.dart and parts: Expected to find ';'
Error in lib/app_component.dart and parts: Expected a class member
Error in lib/app_component.dart and parts: Unexpected token '<'
Error in lib/app_component.dart and parts: Operator declarations must be preceeded by the keyword 'operator'
package:analyzer/analyzer.dart 116 _parseSource
package:analyzer/analyzer.dart 44 parseCompilationUnit
package:angular2/src/transform/directive_processor/rewriter.dart 31 createNgMeta.<async>
dart:async-patch/async_patch.dart 27 _asyncThenWrapperHelper.<fn>
dart:async/zone.dart 1158 _rootRunUnary
dart:async/zone.dart 1037 _CustomZone.runUnary
dart:async/future_impl.dart 131 _FutureListener.handleValue
dart:async/future_impl.dart 637 _Future._propagateToListeners.handleValueCallback
dart:async/future_impl.dart 667 _Future._propagateToListeners
dart:async/future_impl.dart 467 _Future._complete
dart:async/future_impl.dart 52 _SyncCompleter.complete
package:angular2/src/transform/common/logging.dart 27 logElapsedAsync.<async>
dart:async-patch/async_patch.dart 27 _asyncThenWrapperHelper.<fn>
dart:async/zone.dart 1158 _rootRunUnary
dart:async/zone.dart 1037 _CustomZone.runUnary
dart:async/future_impl.dart 131 _FutureListener.handleValue
dart:async/future_impl.dart 637 _Future._propagateToListeners.handleValueCallback
dart:async/future_impl.dart 667 _Future._propagateToListeners
dart:async/future_impl.dart 477 _Future._completeWithValue
dart:async/future_impl.dart 528 _Future._asyncComplete.<fn>
dart:async/zone.dart 1150 _rootRun
dart:async/zone.dart 1026 _CustomZone.run
dart:async/zone.dart 953 _CustomZone.bindCallback.<fn>
dart:async/schedule_microtask.dart 41 _microtaskLoop
dart:async/schedule_microtask.dart 50 _startMicrotaskLoop
dart:isolate-patch/isolate_patch.dart 96 _runPendingImmediateCallback
dart:isolate-patch/isolate_patch.dart 149 _RawReceivePortImpl._handleMessage
package:analyzer/analyzer.dart 116 _parseSource
package:analyzer/analyzer.dart 44 parseCompilationUnit
package:angular2/src/transform/directive_processor/rewriter.dart 31 createNgMeta.<async>
dart:async _SyncCompleter.complete
package:angular2/src/transform/common/logging.dart 27 logElapsedAsync.<async>
[DirectiveProcessor]:
失败,出现4个错误
错误1:lib\app_component.dart第23行第5列和零件:应找到“;”
T foo(T值){
^^^
错误2:lib\app_component.dart第23行第8列和零件:应为类成员
T foo(T值){
^
错误3:lib\app_component.dart和parts的第23行第8列:意外标记'Angular2尚不支持通用方法-我们依赖的是没有这种支持的analyzer版本。请在3.0.0分支的未来版本中查找它。为什么不更新到1.22.0?如果Angular2使用的analyzer版本是n,我不会感到惊讶还不支持通用方法。我建议您更新到Dart 1.22.0和Angular 3.0.0-alpha。我已经尝试过1.22.0和Angular2 3.0.0-alpha,但问题仍然存在。我建议您在中创建错误报告