-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stricter type aliases #5952
Comments
As for the language service displaying the declared name, it's probably better not to do that so that users understand what they're actually dealing with. It would be inappropriate to give users the impression that the language is doing what this proposal asks for with respect to the On the other hand, for a different declaration that does something close to what Haskell's |
As a very poor workaround I'm using empty enums. For example: declare const enum coord {}
declare const enum size {}
type xy = [coord, coord]
type wh = [size, size]
mouseX: coord
mouseY: coord
width: size
height: size
ellipse(x: coord, y: coord, w: size, h: size): this |
also related #4895 |
looks like a dupe of #2477 |
@GoToLoop, that's actually a decent workaround. Thanks! |
Let's say we have an alias for
number
:The
zero
variable, despite being of typecoords
, will act everywhere as though it's a plain number: the language service will say that it's a number, the compiler will treat it as a plain number and so on. However thecoords
type is not just a number because it has some internal structure and because not every value of typenumber
is a value of typecoords
(in other words, the set of values incoords
is smaller than the set of values innumber
).It would be nice if the language service displayed the proper type name in such cases and if the compiler put some constraints on operations with such custom types, e.g.
const zero: coords = 0
should error because0
is of typenumber
which may be (the compiler doesn't know) wider thancoords
.The text was updated successfully, but these errors were encountered: