Attempt to more-frequently use local aliases when printing out types
See original GitHub issueWhen a user imports a type alias like
// ./a.ts
export type Foo = number | string | symbol;
We should try to print out Foo
in error messages like in
// ./b.ts
import { Foo } from "./a.js"
let x: Foo = true;
and in declaration emit like in
// ./c.ts
import { Foo } from "./a.js"
function f(x: Foo) {
return x;
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:27
- Comments:12 (7 by maintainers)
Top Results From Across the Web
How do I temporarily bypass an alias in tcsh?
Most of the time I want the aliased command, which is why I have them. However, sometimes I want the unaliased command. Without...
Read more >Emacs compilation mode won't see bash alias - Stack Overflow
If I use M-x shell then type the alias, it is fine. I tried sourcing .bashrc from /etc/profile, from ~/.profile, ~/bash_env, anything I...
Read more >Postfix Configuration Parameters
The alias databases that are used for local(8) delivery. See aliases(5) for syntax details. Specify zero or more "type:name" lookup tables, separated by ......
Read more >8. Configuration Reference — BIND 9 9.18.8 documentation
The operational functionality of BIND 9 is defined using the file ... More information on those names can be found in the description...
Read more >Learning the Basics - Gradle User Manual
These can be declared as local repositories, using a local filesystem path to ... Just like with project and task names, you can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As long as the
Identity<>
trick doesn’t break, right?https://github.com/microsoft/TypeScript/issues/34556
There are cases where
Foo
is actually a generic type. AndFoo<T>
is 100+ lines long becauseT
is 100+ lines long.But if
Foo<T>
is “expanded”, the expanded type could be like 5 lines.The
Identity<>
trick forces TS to always expand the type, at the moment.Pick and Omit suffer from this problem, too.
Pick<T, K>
If
T
is 100+ properties andK
is 2 properties, the emit can be 100+ lines long. In such cases, I always tell people to write their own version ofPick
andOmit
using theIdentity<>
trick.https://github.com/microsoft/TypeScript/issues/34793
I guess I should find/file a separate issue for this, and locate all the relevant issues. (Like a meta issue regarding type display?)
But it seems like TS doesn’t really give developers a way to explicitly control how they want a type to “expand” in emit/hover, at the moment.
To TS, as long as the types behave well, then all is good; it doesn’t matter if the type looks simple or complicated.
Except, to developers, if the type looks complicated/long/verbose, then it’s extra cognitive overhead. That, and hover and error messages tend to truncate long types.
I’m not sure how to phrase this properly.
I think it’s fine to have heuristics for TS to automatically determine how to “present” a type. Given a type, there could be a million different ways to express it syntactically.
However, there needs to be a way for a programmer to step in and say, “Your heuristics are bad.”, “Expand this type.”, “Don’t expand this type.”, “Use
typeof x
instead ofX
”, etc.Because, sometimes, the 100+ line type is more readable than the 5 line type. Mostly, it’s the other way around. Sometimes, aliases are easier to understand. Other times, the full expanded type is easier. There’s no way an algorithm can display a type such that it’ll always be “easiest” to read. It’s rather subjective, I’ve found.
Also relevant, https://github.com/microsoft/TypeScript/issues/32977
The problem with that solution is that it does not help for .d.ts emit and error message elaboration.
Those 2 cases are the main motivators, for me.
See,
https://github.com/microsoft/TypeScript/issues/35654
https://github.com/microsoft/TypeScript/issues/34556
When .d.ts emit goes wrong and it emits too much, the emitted files become unreadable, or cause emit times to blow up
When it emits too little, it can also impact readability negatively, the compiler needs to put in more work to resolve the type for downstream consumers, increasing check times, causing earlier max depth errors, etc
Error elaborations are also affected by emit being too small, or too large