In scala multiple inheritance, how to resolve conflicting methods with same signature but different return type?
Tag : scala , By : Tim Tyrrell
Date : March 29 2020, 07:55 AM
I wish this helpful for you I'm afraid there is no way to do that. The super[A].work way works only if A and B have the same return types. Consider this: class D extends B
....
val test: List[B] = List(new C(), new D())
test.map(b => b.work) //oops - C returns a String, D returns an Int
|
Why can't I indirectly return an object literal to satisfy an index signature return type in TypeScript?
Date : March 29 2020, 07:55 AM
this will help This behavior is going away. Starting at whatever release comes after TypeScript 1.8 (or right now if you're using the bleeding-edge compiler), you will no longer see this error when the originating expression for a type is an object literal. var x: number = y;
// Error: string does not contain a function called 'ToUpper'
var x: (n: string) => void = (s) => console.log(s.ToUpper());
var x: { [n: string]: Car; };
var y: { [n: string]: Animal; };
x = y; // Error: Cars are not Animals, this is invalid
var x: { [n: string]: Car; };
var y: { name: Car; };
x = y; // Error: y doesn't have an index signature that returns a Car
var c: Car;
// Error, or not?
var x: { [n: string]: Car } = { 'mine': c };
var c: Car;
var a: Animal;
// OK
var x: { [n: string]: Car } = { 'mine': c };
// Not OK: Animal is not Car
var y: { [n: string]: Car } = { 'mine': a };
function a(): StringMap {
return { a: "1" }; // OK
}
function b(): StringMap {
var result: StringMap = { a: "1" };
return result; // OK
}
function c(): StringMap {
var result = { a: "1" };
return result; // Error - result lacks index signature, why?
}
|
Can I have one @Query for multiple JPA repository methods with different signature and return type?
Date : March 29 2020, 07:55 AM
wish of those help Well, I realized that it is possible to declare query as String. But more elegant way suggestions are still welcome, may be I am missing something. public interface UserRepository extends JpaRepository<User, Long> {
String QUERY_TEXT = "SELECT u FROM User u WHERE ...";
... some repository methods ...
@Query(QUERY_TEXT)
List<User> findUsersByCustomCriteria(String criteria);
@Query(QUERY_TEXT)
Set<User> findUsersByCustomCriteria(String criteria, Sort sort);
@Query(QUERY_TEXT)
Page<User> findUsersByCustomCriteria(String criteria, Pageable pageable);
}
|
Does a method signature in declaration typescript include return types and paramter types (basically the type annotation
Date : March 29 2020, 07:55 AM
wish help you to fix your issue What I meant was how could i get the return types of functions that are there in declaration typescript files using typescript services library.
|
Python metaprogramming: generate a function signature with type annotation
Tag : python , By : Mossy Breen
Date : March 29 2020, 07:55 AM
it should still fix some issue Instead of creating a function with annotations, it's easier to create a function and then set the annotations manually. params = [inspect.Parameter(param,
inspect.Parameter.POSITIONAL_OR_KEYWORD,
annotation=type_)
for param, type_ in args.items()]
new_fn.__signature__ = inspect.Signature(params)
new_fn.__annotations__ = args
def gen_fn(args: Dict[str, Any]) -> Callable:
def new_fn():
pass
params = [inspect.Parameter(param,
inspect.Parameter.POSITIONAL_OR_KEYWORD,
annotation=type_)
for param, type_ in args.items()]
new_fn.__signature__ = inspect.Signature(params)
new_fn.__annotations__ = args
return new_fn
print(inspect.signature(gen_fn({'a': int}))) # (a:int)
print(get_type_hints(gen_fn({'a': int}))) # {'a': <class 'int'>}
def new_fn(*args, **kwargs):
...
|