Dart Mirrors in JS: type '_ListConstructorSentinel' is not a subtype of type 'int' - dart-mirrors

The following code executes fine on the VM, but fails with
"'_ListConstructorSentinel' is not a subtype of type 'int'"
when converted to javascript via Dart2JS. I'm using "pub run test -p chrome " to run the code.
import "dart:mirrors";
main() {
TypeMirror tm = new TypeToken<List<String>>().typeMirror;
(tm as ClassMirror).newInstance(const Symbol(""), []);
}
class TypeToken<T> {
TypeMirror get typeMirror => reflectType(T);
}
StackTrace:
type '_ListConstructorSentinel' is not a subtype of type 'int'
error.dart.browser_test.dart.js 4385:15 dart.wrapException
error.dart.browser_test.dart.js 4604:13 dart.intTypeCheck
error.dart.browser_test.dart.js 36709:11 Isolate.dart.List.static.List_List.H.computeSignature.func
error.dart.browser_test.dart.js 13292:31 JsMethodMirror.dart.JsMethodMirror._invoke$2
error.dart.browser_test.dart.js 12724:21 JsClassMirror.dart.JsClassMirror._getInvokedInstance$3
error.dart.browser_test.dart.js 12054:30 JsTypeBoundClassMirror.<fn>
error.dart.browser_test.dart.js 12058:19 JsTypeBoundClassMirror.dart.JsTypeBoundClassMirror.newInstance$3
error.dart.browser_test.dart.js 85680:232 dart.main0
error.dart.browser_test.dart.js 15329:32 dart.Future.static.Future_Future$sync.H.computeSignature.func
error.dart.browser_test.dart.js 97668:16 IframeListener_start_closure.dart.IframeListener_start_closure.call$0
Am I doing something that shouldn't be allowed, or is this a bug? If it's a bug, is there any way to work around it?
Thanks in advance!

Looks like this is a known issue: github.com/dart-lang/sdk/issues/21927

Related

Using enums in Typescript's generics with strictFunctionTypes

I have the following code (TS playground link):
const enum Enum { A, B, C }
interface Args {
e: Enum.A;
}
interface GenericClass<A> {
new (args: A) : void;
}
class TestClass {
constructor(args: Args) {}
}
function func<A>(C: GenericClass<A>, args: A) {
return new C(args);
}
func(TestClass, { e: Enum.A });
The last line [1] throws an error with strictFunctionTypes enabled:
Argument of type 'typeof TestClass' is not assignable to parameter of type 'GenericClass<{ e: Enum; }>'.
Types of parameters 'args' and 'args' are incompatible.
Type '{ e: Enum; }' is not assignable to type 'Args'.
Types of property 'e' are incompatible.
Type 'Enum' is not assignable to type 'Enum.A'.
That's strange because I accept exact enum value Enum.A and I pass the exactly same value Enum.A into function.
I know I can use type casting { e: <Enum.A>Enum.A }, but it looks strange for me. Is here a way to fix this problem without type casting?
I am not 100% sure why this happens, but I belive that when inferring A the compiler will consider both places where A appears and decide that the widest possible type is { e:Enum} based on the fact that object literals don't usually infer literal types for their fields. After the inference it will see that under strict functions the type is not compatible with the class. Under this theory, if we decrees the priority of the second inference site, we should get the correct type for A,. We can do this using an intersection type A&{} (I am not sure where exactly I read this but it was in a github issue and a member of the compiler team mentioned that this way of decreasing inference priority is probably going to work for the foreseeable future) .
Again that is mostly an educated guess, but the solution works :
const enum Enum { A, B, C }
interface Args {
e: Enum.A;
}
interface GenericClass<A> {
new (args: A) : void;
}
class TestClass {
constructor(args: Args) {}
}
function func<A>(C: GenericClass<A>, args: A & {}) {
return new C(args);
}
func(TestClass, { e: Enum.A });
playground link

Error while building #angular/material2

I just took the latest version of Angular material 2 .
I try to build and it gives gulp build error. I am sure something is wrong , can anyone else try if its building fine.
TSError: тип Unable to compile TypeScript
node_modules/#types/run-sequence/node_modules/#types/gulp/index.d.ts (15,15): Interface 'Gulp' incorrectly extends interface 'Orchestrator'.
Types of property 'task' are incompatible.
Type 'AddMethod' is not assignable to type '{ (name: string): Task; (name: string, fn: TaskFunc): void; (name: string, dep: string[], fn: Tas...'.
Type 'Orchestrator' is not assignable to type 'Task'.
Property 'fn' is missing in type 'Orchestrator'. (2430)
tools/gulp/tasks/ci.ts (4,17): Argument of type 'string[]' is not assignable to parameter of type 'TaskFunction'.
Type 'string[]' provides no match for the signature '(done: (error?: any) => void): any'. (2345)
Node version : v6.9.1
gulp version: 3.9.1
Tried this solution : Unable to run project under Gulp
did not work .
Its great if someone can help me fix this, at least even if I know for sure that its working for others , I will try to fix it.

Cannot convert value of type string to expected argument type Int

I was playing around with code. I found on GitHub (https://github.com/avijeets/ConnectFour) and was thoroughly stumped on an error I couldn't clear out.
The error is:
"Cannot convert value of type '[[CFCellState]]' to expected argument
type 'Int'"
Code from the top of the VC where CFCellState is defined:
enum CFCellState: CustomStringConvertible {
case empty
case occupied(CFPlayer)
var description: String {
switch self {
case .empty:
return "empty"
case .occupied(let player):
return player.description
}
}
}
Code from where the error occurs:
self.init(player: current!, opponent: opponent!, columns:ConnectFour.boardFrom(json: queryItems[1].value!)!)
Try this instead:
self.init(player: current!, opponent: opponent!, board: ConnectFour.boardFrom(json: queryItems[1].value!)!)
In order for this to work, you may need to remove the private keyword from this line in ConnectFour.swift file (look around line #98):
private init(player: CFPlayer, opponent: CFPlayer, board: [[CFCellState]]) { ....

Implicit coercion of a value of type Vector.<X> to an unrelated type Vector.<X>

I've got line of code
var enemies:Vector.<Unit> = _map.getEnemiesForFraction(_fraction);
where _map.getEnemiesForFraction(_fraction) is
public function getEnemiesForFraction(fraction:String):Vector.<Unit>
{
return _enemiesByFraction[fraction];
}
It compiles and works fine, but FlashBuilder keep annoying me with error
Implicit coercion of a value of type Vector.<Unit> to an unrelated
type Vector.<Unit>.
Why? How to get rid of this? Neither restart nor clean, doesn't work.

AS3: Error #1034: Type Coercion failed: cannot convert to flash.display.DisplayObject

having some trouble with hitTestObject and now Flash is telling me it can't convert my ship to a display object.. my problem is the ship class extends Sprite to begin with so I don't know what's going on:
Compile error shows this:
TypeError: Error #1034: Type Coercion failed: cannot convert Ship$ to flash.display.DisplayObject.
at Control/controlgame()
Control / controlgame() is this:
function controlgame(e:Event) {
for (var i = 0; i < wprojectiles.length; i ++) {
if (wprojectiles[i].x < -200 || wprojectiles[i].x > 750 || wprojectiles[i].y < -200 || wprojectiles[i].y > 600) {
parent.removeChild(wprojectiles[i]);
wprojectiles.splice(i,1);
}
if (wprojectiles[i].hitTestObject(Ship)) {
parent.removeChild(wprojectiles[i]);
wprojectiles.splice(i,1);
}
}
}
Using the debugger, I get this error:
TypeError: Error #1034: Type Coercion failed: cannot convert Ship$ to flash.display.DisplayObject.
at Control/controlgame()[C:\Users\Harry\Desktop\Flash Games\Games\Dodge\Control.as:29]
Line 29, seen in the above snippet, is this:
if (wprojectiles[i].hitTestObject(Ship)) {
Tearing my hair out here, tried everything I could think of and I get this error every single time, no matter what I do! Help would be so badly appreciated!
Thanks in advance.
e: if it bears relevance, this is my document class file
Where did you declare Ship? It looks like you're using a Class for your test instead of an instance... do you have something like Ship = new ShipClass() somewhere?