Declare a polymorphic class that extends another polymorphic class - flowtype

I'm writing a component in React that expects to receive a component, that owns a specific field onPropChange to be accessed via a ref, as a prop.
/* #flow */
import * as React from 'react';
type onPropChangeObject<Props> = {
[key: $Keys<Props>]: (newValue: any) => void
}
declare class PropWatchableComponent<DefaultProps, Props: Object, State>
extends React.Component<DefaultProps, Props, State>
{
onPropChange?: onPropChangeObject<Props>;
}
But the type checking fails with multiple errors in the latest version of Flow (0.39.0) as seen here
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> { ^ undefined. Did you forget to declare some incompatible instantiation of `DefaultProps`?. This type is incompatible with
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> { ^ some incompatible instantiation of `DefaultProps`
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> { ^ undefined. Did you forget to declare some incompatible instantiation of `State`?. This type is incompatible with
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> { ^ some incompatible instantiation of `State`
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {
^ DefaultProps. This type is incompatible with
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {
^ undefined. Did you forget to declare DefaultProps?
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {
^ State. This type is incompatible with
8: declare class PropWatchableComponent<DefaultProps, Props: Object, State> extends React.Component<DefaultProps, Props, State> {
^ undefined. Did you forget to declare State?
What's all this talk about undefined? I'm clearly declaring both DefaultProps and State as type parameters. What did I forget?

see this, you should use interface instead `class'.
https://flowtype.org/try/#0PQKgBAAgZgNg9gdzCYAoAlgWwA5wE4AuYASgKYCGAxkVHnJmAOR4XWMDcqqBAntqWDgA7AAp1sAYQAW5IQHNSAeQBGAK1LUAPGLjYAzgC4wK9dQB8YALxgA3qjBgA2gGtSPIwBIA0m73bxemYAukYAFEKkCABq5DAArqRGsjwAlFYWAG5w6AAmqAC+XOhCBKR4UFQCOtgA6uQElDLKMKQS9LgRJf66hsZqGgQWdg4AkNgBRtV6nA72DoKi4tKyCgD8RsLVy-JK-VpTZpyF86hQcULU6MJgCPWNWzI7eqE1eOTY-DlGEjDken7VOoNJotNo4YSkLomAZmMxpGyFVCUX7-MAAZVucjBHUhRFIAA9SkIcnoSKwCAA6bEQkq2OabJaPBQbRa6bYKaFaTmDKx00bjXRhchpSwWSjCPRwFoU+ByUKMKgEK5CRgAGjAwrmhURt2BDxWpGeGPIWPaNIIKSAA

Related

Symfony 3.4 apply tag on all classes who implement same interface

I'm working with a Symfony 3.4 (PHP 7.2, update to 7.4 soon) project. I have some classes who extends an abstract class and i would like all my classes got the same constant name (constant have value different in each class). I'm starting with a pattern like this :
abstract class AbstractClass
{
abstract public function getConstant(): string;
}
final class Foo extends AbstractClass
{
const MY_CONST = 'foo';
public function getConstant(): string
{
return self::MY_CONST;
}
}
final class Bar extends AbstractClass
{
const MY_CONST = 'bar';
public function getConstant(): string
{
return self::MY_CONST;
}
}
// echo $foo->getConstant() : 'foo'
// echo $bar->getConstant() : 'bar'
The goal: if a class who extends AbstractClass don't have MY_CONST, i want return an message error.
I have excluded theses solutions :
I can't add a constant in an interface (maybe in PHP 8 ?)
I can't use "abstract factory" pattern for a constant (in my code it runs with getConstant() method
I can't use a static property
The only way i have found is : implement an interface and tag the interface like explain in documentation. With compilerpass, helped with ReflexionClass, i will check if constant name exist, and if not: thrown an error or something like this.
So, i've edit like this :
final class Foo extends AbstractClass implements MyCustomInterface
{
// ...
}
final class Bar extends AbstractClass implements MyCustomInterface
{
// ...
}
The interface :
interface MyCustomInterface
{
}
Adding tag in AppKernel.php
protected function build(ContainerBuilder $container): void
{
$container
->registerForAutoconfiguration(MyCustomInterface::class)
->addTag('my_custom_tag');
}
And a compilerpass :
class MyCustomPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container): void
{
if (!$container->has(MyCustomInterface::class)) {
dump('No interface found');
return;
}
$definition = $container->findDefinition(MyCustomInterface::class);
$taggedServices = $container->findTaggedServiceIds('my_custom_tag');
dump($taggedServices);
}
}
The fun begin here...if i have only ONE class who implement the interface, $taggedServices find the service. BUT, if more than one class implements interface, no class are found...
I don't find where i am wrong. Do i need to implements AbstractClass instead of children classes ?

The argument type 'UserRepository/*1*/' can't be assigned to the parameter type 'UserRepository/*2*/'

In my main.dart I get the following error:
The argument type 'UserRepository/1/' can't be assigned to the parameter type 'UserRepository/2/'
The code is the following:
void main() {
WidgetsFlutterBinding.ensureInitialized();
final UserRepository _userRepository = UserRepository();
BlocSupervisor.delegate = SimpleBlocDelegate();
runApp(BlocProvider(
create: (context) => AuthenticationBloc(userRepository: _userRepository)
..add(AppStarted()),
child: Home(userRepository: _userRepository)));
}
And the class AuthenticationBloc looks like this:
class AuthenticationBloc
extends Bloc<AuthenticationEvent, AuthenticationState> {
final UserRepository _userRepository;
AuthenticationBloc({#required UserRepository userRepository})
: assert(userRepository != null),
_userRepository = userRepository;
#override
AuthenticationState get initialState => Uninitialized();
...
How can I fix this issue?
I've had the same error when i had two imports like this:
import 'package:app/repository.dart';
// In other file
import 'package:app//repository.dart';
Because of that second import which has double '/' it was throwing an error.

Is FungibleAsset compatible with Java CorDapps?

This has been asked here but I will try to approach the question differently.
A quick review of Corda's code:
interface FungibleState<T : Any> : ContractState {
val amount: Amount<T>
}
FungibleAsset then extends FungibleState:
interface FungibleAsset<T : Any> : FungibleState<Issued<T>>, OwnableState {
override val amount: Amount<Issued<T>>
#get:SerializableCalculatedProperty
val exitKeys: Collection<PublicKey>
fun withNewOwnerAndAmount(newAmount: Amount<Issued<T>>, newOwner: AbstractParty): FungibleAsset<T>
}
If I use FungibleAsset in a Java CorDapp:
public class MyFungibleAsset implements FungibleAsset<Currency> {
#NotNull
#Override
public Amount<Issued<Currency>> getAmount() {
return null;
}
...}
it will raise 2 errors when I build the project (IntelliJ won't highlight any error during editing):
error: MyFungibleAsset is not abstract and does not override abstract method getAmount() in FungibleState
error: getAmount() in MyFungibleAsset cannot implement getAmount() in FungibleState
public Amount<Issued<Currency>> getAmount() {
^
return type Amount<Issued<Currency>> is not compatible with Amount<Issued<? extends Currency>>
where T is a type-variable:
T extends Object declared in interface FungibleState
I assume this has something to do with FungibleState's getAmount returning Amount<T> whereas FungibleAsset's getAmount returns Amount<Issued<T>> ? I don't get an error in kotlin.

Angular Http method not found

I've used this as core project for one of my project and I am stuck with it.
I trying to use the http method but it fails.
I've tried add the HttpClientModule to the app.module but still nothing.
The error that i get is :
app.ae014c5e7b696f87de83.bundle.js:107 ERROR TypeError:
Cannot read property 'method' of undefined
All I did in the app.component.ts file add
export class AppComponent extends BaseComponent implements OnInit {
constructor(
private readonly i18nStore: Store<I18NState>,
private readonly config: ConfigService,
private http: HttpClient,
#Inject(PLATFORM_ID) public platformId: Object
) {
super();
// TODO: ngx-i18n-router
// private readonly i18nRouter: I18NRouterService) {
}
ngOnInit(): void {
this.i18nStore.dispatch(new Init(this.config.getSettings('i18n')));
}
createUserA(): void {
this.http.get<any>('https://swapi.co/api/people/1')
.subscribe(data => console.log('data', data));
}
}
Bot get and post don't work.
I've imported :
import { HttpClient } from '#angular/common/http';
Add to your app.component.ts
contructor(private http : HttpClient) {}

Hadoop Map output IOException when emitting subclass of a class defined in Configuration as an ouput

I have 3 simple classes:
public abstract class Container implements WritableComparable<Container> {} //empty
public class WeightedEdge extends Container { ... }
public class NodeWeightContainer extends Container { ... }
The Map phase was configured as such
JobConf createGraphPConf = new JobConf(new Configuration());
Job job = new Job(createGraphPConf);
...
createGraphPConf.setMapOutputValueClass(Container.class);
However I am receiving this error:
java.io.IOException: Type mismatch in value from map: expected org.hadoop.test.data.util.Container, recieved org.hadoop.test.data.WeightedEdge
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:1018)
at org.apache.hadoop.mapred.MapTask$OldOutputCollector.collect(MapTask.java:591)
at org.hadoop.test.map.CreateGPMap.map(CreateGPMap.java:33)
at org.hadoop.test.map.CreateGPMap.map(CreateGPMap.java:19)
at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:50)
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:435)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:371)
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:210)
Why I can't return a subclass of a class that was defined in the configuration? Is there a way around it? The problem is that my Map phase has to emit two distinct object types.
You can not return a subclass of a class that was defined in the configuration because Hadoop explicitly checks class type specified in setMapOutputValueClass and the type it receives from Mappers.
It does so because it needs to serialize/deserialize objects you emit from mappers. When it performs deserialization it creates new object of type that is specified in setMapOutputValueClass call and then uses methods of WriteableComparable interface to fill newly created object with data.
To be able to emit different object types you may define container non-abstract class and place actual object and its type identifier inside
public enum ELEM_TYPE { WE, WECONTAINER }
public class Container implements WritableComparable<Container>
{
ELEM_TYPE type; //actual element type -
// WeightedEdge or NodeWeightContainer
object value;
//WritableComparable implementation
// that casts value to the appropriate type
}
public class WeightedEdge { ... }
public class NodeWeightContainer { ... }
I faced the same problem today. There is a Writable class org.apache.hadoop.io.GenericWritable which can be used to address this problem. You need to extend the class and implement an abstract method:
public class Container extends GenericWritable {
private static Class[] CLASSES = {
WeightedEdge.class,
NodeWeightContainer.class,
};
protected Class[] getTypes() {
return CLASSES;
}
}
public class WeightedEdge implemets Writable {...}
public class NodeWeightContainer implements Writable {...}
Now you can use the class Container as the output value type of your mapper.
Important: Your actual map output classes (WeightedEdge and NodeWeightContainer) must implement the Writable interface.

Resources