type-inference Questions
5
Solved
I have an array like:
const arr = ['a', 'b'] as const;
// type: readonly ["a", "b"]
Now I want to join the strings in the array:
const joined = arr.join('');
// type: string
M...
Dhu asked 22/6, 2022 at 22:21
1
I've finally upgraded a big project to .NET Core and C# 12, and was excited because I can now use nullable reference types. But I promptly discovered that variables created by type inference are nu...
Trometer asked 18/1, 2024 at 18:2
6
Solved
In VS2012, you can hover over a typescript variable and it will show you the inferred type. Is there a similar feature in webstorm?
Andie asked 17/9, 2013 at 1:44
3
Solved
Consider
void Main()
{
var list = new[] {"1", "2", "3"};
list.Sum(GetValue); //error CS0121
list.Sum(s => GetValue(s)); //works !
}
double GetValue(string s)
{
double val;
double.TryParse...
Wishywashy asked 12/10, 2011 at 20:3
9
Solved
I've seen this answered before, but they don't seem to cover this specific use case (or they don't work/help)
import {Route} from 'vue-router';
export const detailRoute = {
path: '/detail/:id',...
Newly asked 10/5, 2017 at 18:21
6
Solved
I've just started playing a little with Haskell... I want to write a function of the same type of the identity. Obviously, not equivalent to it. That would be something like,
myfunction :: a ->...
Gilbertina asked 1/9, 2012 at 19:39
8
Solved
Code (spring-web 5.1.2)
public static void main(String[] args) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.set(HttpHeaders.AUTHORIZATION,...
Nakasuji asked 19/2, 2019 at 21:33
2
Assume we have this function:
function returnNever(): never {
throw new Error();
}
When creating an IIFE, the code that comes after it becomes marked as unreachable:
(async () => {
let b: str...
Tangled asked 6/11, 2019 at 14:51
1
Solved
I don't fully understand why the following code, doesn't work:
package org.example;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
...
Veterinarian asked 6/7, 2023 at 12:36
3
Solved
I am stumped by this and cannot figure out how to do this without a second function:
interface Fixed { a: number }
const fn = <A, B extends {} = {}>(b: B) => {
return b
}
fn({ a: 1 }) //...
Catty asked 31/8, 2020 at 21:17
2
On JetBrains open day 2019 it was said that the Kotlin team researched contracts and tried to implement context contracts which allow calling a function only in some context, for example, a functio...
Schlessinger asked 28/9, 2019 at 23:9
4
Solved
In a react-native application, I have the style
const styles = StyleSheet.create({
text: {
textAlign: "center"
},
})
used in <Text style={styles.text} />, but the tsc compiler gives the...
Complemental asked 30/3, 2017 at 15:6
2
Consider
const pairer = <T,>(a: T, b:T) => ({a, b})
const mypair = pairer(3n, true)
This is an error in TypeScript 4.9, namely
Argument of type boolean is not assignable to parameter of ...
Caber asked 22/12, 2022 at 19:55
1
I have found a way to import scss variables into ts and js using this article
Basically the approach is:
Create a modular scss file containing your scss variables, or import them from the original ...
Morsel asked 1/11, 2022 at 12:15
1
Solved
Why does this compile:
fn main() {
let xs = [||1, ||2, ||3];
}
but this does not?
fn main() {
let xs = [(||1, 1), (||2, 2), (||3, 3)];
}
error[E0308]: mismatched types
--> src/main.rs:2:29
...
Shon asked 19/10, 2022 at 12:41
5
Solved
The type inference engine of Haskell is much more powerful than Scala's. In Haskell I rarely have to explicitly write the types whereas in Scala the types can only be inferred in expressions but no...
Coco asked 29/8, 2011 at 18:17
3
Solved
pandas function read_csv() reads a .csv file. Its documentation is here
According to documentation, we know:
dtype : Type name or dict of column -> type, default None Data type
for data or co...
Janessajanet asked 7/12, 2015 at 17:2
1
Solved
I try in vain to narrow discriminated types with object destructuring. I thought Typescript is able to infer them since v4.4.
However, I cannot do it in this code (just an example of idea):
type Wr...
Pathless asked 5/8, 2022 at 14:44
1
I'm trying to use Yup to define a schema and generate a Typescript Type that I can use for my objects.
Using InferType seems to work fine for strings and objects, but there's unexpected behavior fo...
Idolism asked 22/1, 2021 at 22:33
3
Solved
IntelliJ shows type hints for local variables in Kotlin as shown here:
This makes it easy to see the type of variables even if their types are inferred.
Java 10 introduces type inference for Java ...
Halm asked 26/6, 2019 at 15:0
6
Solved
As I understand it, both decltype and auto will attempt to figure out what the type of something is.
If we define:
int foo () {
return 34;
}
Then both declarations are legal:
auto x = foo();
cout...
Encephalitis asked 23/8, 2012 at 2:41
3
Solved
I've read some articles about Covariance, Contravariance, and Invariance in Java, but I'm confused about them.
I'm using Java 11, and I have a class hierarchy A => B => C (means that C is a s...
Aw asked 16/5, 2022 at 12:16
2
Solved
I encountered this strange behaviour when reading this post, and the core question of this post is when you matching (&k, &v) = &(&String, &String) , k and v will get the type S...
Cliff asked 4/4, 2022 at 3:43
4
This snippet works as expected play.golang.org/p/VuCl-OKMav
i := 10
next := 11
prev, i := i, next
However this nearly identical snippet gives non-name f.Bar on left side of := play.golang.org/p/...
Morty asked 25/1, 2014 at 1:11
1
Solved
Consider the following article from the JLS (§15.13.1)
A method reference expression ending with Identifier is exact if it satisfies all of the following:
If the method reference expression has t...
Sufflate asked 21/2, 2022 at 16:38
1 Next >
© 2022 - 2025 — McMap. All rights reserved.