-
Notifications
You must be signed in to change notification settings - Fork 3k
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
refactor(interfaces): replace type aliases #3045
Conversation
Generated by 🚫 dangerJS |
Seems like a good solution at first glance. |
TIL: documentation can be out-of-date. Anyway, with the interfaces, you could have it working now, instead of in January (maybe) with TS 2.7. |
Totes. Btw rereading my last comment it might have seemed like I meant “at first glance” to mean that it’s not a good solution after all. Whoops! Not what I meant. I just meant that I haven’t tested it or seen if it has any other impacts in real usage. Someone on the core team will review hopefully. |
No worries. I took it the way you intended it. |
I started to think this would be a breaking change because // as an alias
type UnaryFunction_alias<T, R> = (source: T) => R;
type OperatorFunction_alias<T, R> = UnaryFunction_alias<Observable<T>, Observable<R>>;
// as an interface
interface UnaryFunction_interface<T, R> { (source: T): R; }
interface OperatorFunction_interface<T, R> extends UnaryFunction_interface<Observable<T>, Observable<R>> { }
declare let usingAlias: OperatorFunction_alias<void, void>;
declare let usingInterface: OperatorFunction_interface<void, void>;
// no type error
usingAlias = usingInterface; It would have been very unlikely anyone depended on it anyway. |
Interestingly, this is how I first implemented this when working on it, but switched it because I thought it was more readable for other contributors. (interfaces for functions is pretty weird, IMO, but probably a personal preference thing) If this solves a problem that's blocking you @jayphelps or the documentation efforts in general, I'll happily merge. |
Also, if @jayphelps says this solves a problem for our docs, we should add a test to make sure we don't break it in the future. |
This is another one that could use a snippet test - to ensure the inferred type is what's expected. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description:
Regarding this issue - that was opened in the TypeScript repo - there is a simple resolution: replace the type aliases with interfaces.
The TypeScript documentation for advanced types includes these comments in the Type Aliases section:
I can see that the issue has been labelled as a bug, but the referenced documentation suggests otherwise.
cc/ @jayphelps @benlesh
Related issue (if exists): microsoft/TypeScript#19198