static-typing

TS branded string as key of the object

◇◆丶佛笑我妖孽 提交于 2020-06-27 18:06:09
问题 Imagine, that I have class Foo with string identifier. class Foo { id = '123' as FooId; } I try to ensure static typing of it using a brand enum. enum FooIdBranding {} type FooId = string & FooIdBranding; So now, my goal is specific object, where the key is FooId and the value is Foo . type fooCache = { [key: FooId]: Foo }; Unfortunately, it doesn't work: TS1023: An index signature parameter type must be 'string' or 'number' I thought, that the Record is my solution, but is doesn't work too.

TS branded string as key of the object

最后都变了- 提交于 2020-06-27 18:04:23
问题 Imagine, that I have class Foo with string identifier. class Foo { id = '123' as FooId; } I try to ensure static typing of it using a brand enum. enum FooIdBranding {} type FooId = string & FooIdBranding; So now, my goal is specific object, where the key is FooId and the value is Foo . type fooCache = { [key: FooId]: Foo }; Unfortunately, it doesn't work: TS1023: An index signature parameter type must be 'string' or 'number' I thought, that the Record is my solution, but is doesn't work too.

How to force static typing in python [duplicate]

旧巷老猫 提交于 2020-04-05 15:06:34
问题 This question already has answers here : How to use type hints in python 3.6? (3 answers) Closed 2 years ago . Since static typing is available in Python 3.6, is it possible to force static typing for a python project or set of python files? 回答1: You can use annotations in Python3, which might help you get some benefits of static typing. However if static typing were to be completely enforced in Python, then it won't be Python anymore. It's a duck-typed dynamic language, and would loose all

How to use static type checking using Dict with different value types in Python 3.6?

ぃ、小莉子 提交于 2020-01-14 14:48:30
问题 Trying to use static types in Python code, so mypy can help me with some hidden errors. It's quite simple to use with single variables real_hour: int = lower_hour + hour_iterator Harder to use it with lists and dictionaries, need to import additional typing library: from typing import Dict, List hour_dict: Dict[str, str] = {"test_key": "test_value"} But the main problem - how to use it with Dicts with different value types, like: hour_dict = {"test_key": "test_value", "test_keywords": ["test

Is float slower than double? Does 64 bit program run faster than 32 bit program?

て烟熏妆下的殇ゞ 提交于 2020-01-09 19:47:07
问题 Is using float type slower than using double type? I heard that modern Intel and AMD CPUs can do calculations with doubles faster than with floats. What about standard math functions ( sqrt , pow , log , sin , cos , etc.)? Computing them in single-precision should be considerably faster because it should require less floating-point operations. For example, single precision sqrt can use simpler math formula than double precision sqrt . Also, I heard that standard math functions are faster in

Typed metaprogramming languages [closed]

你说的曾经没有我的故事 提交于 2019-12-31 20:11:10
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I want to do some metaprogramming in a statically typed language, where both my programs and my meta-programs will be typed. I mean

Typed metaprogramming languages [closed]

冷暖自知 提交于 2019-12-31 20:09:43
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . I want to do some metaprogramming in a statically typed language, where both my programs and my meta-programs will be typed. I mean

Typescript abstract class static method not enforced

自作多情 提交于 2019-12-24 10:16:00
问题 I have this simple code in TypeScript: abstract class Config { readonly NAME: string; readonly TITLE: string; static CoreInterface: () => any } class Test implements Config { readonly NAME: string; readonly TITLE: string; } Even though the CoreInterface() member is missing in the Test class, TypeScript does not complain. Why is this? I need every derived class to provide some metadata about itself in the CoreInterface() static function. I know I could just extend the Config class and have

What does “no global type inference” mean regarding Scala?

大城市里の小女人 提交于 2019-12-21 07:14:17
问题 I have read that Scala's type inference is not global so that is why people must place type annotations on the methods. (Would this be "local" type inference?) I only a little understand that the reason is from its object-oriented nature, but clarity eludes me. Is there an explanation for "global type inference" and why Scala cannot have it that a beginner might understand? 回答1: The typical example for a global type inference is Hindley-Milner: It takes a given program and "calculates" all