-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Don't suggest undefined | null
properties
#43117
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
Comments
The issue you're having is related specifically to the ts-toolbelt package. You might have better luck opening an issue in their repository for what you're dealing with. |
@RA80533 I'm pretty sure the purpose of that library / the type is to explicitly provide the properties from the other union types with an |
It appears so. In ts-toolbelt/Strict.ts, we can see that |
@MartinJohns understands. Moving the @RA80533 the issue is not specific to |
@wojpawlik If I am understanding your problem correctly, I believe it is implementation-specific. That would mean that, just as it existed in ts-toolbelt, the problem would exist in your implementation if it was written the same way. Take a look at the following snippet: export type Result<TValue, TError = unknown> = Result.Success<TValue> | Result.Failure<TError>;
export namespace Result {
export class Success<T> {
public constructor (public readonly value: T) {}
public isSuccess(): this is Result.Success<T> {
return this.constructor.name === Result.Success.name;
}
public isFailure(): this is Result.Failure<T> & never {
return false;
}
}
export class Failure<T> {
public constructor (public readonly error: T) {}
public isSuccess(): this is Result.Success<T> & never {
return false;
}
public isFailure(): this is Result.Failure<T> {
return this.constructor.name === Result.Failure.name;
}
}
} declare function f<T>(): Result<T>; TypeScript will hint at the existence of Is this the kind of behavior you're looking for? |
It's already possible to filter out I think it would be very confusing to do this in general; we can't assume what's intended by this sort of property. |
I'm suggesting to just hide it from suggestions without affecting typechecking, not to disallow accessing it. I don't think there's a way to narrow a value and end up with less properties than one started with. I'm trying to accurately type an API with an undiscriminated union with 35 variants (no classes @RA80533). My proposal to add discriminators was rejected. And |
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Suggestion
π Search Terms
undefined null properties autocomplete autocompletion suggest
β Viability Checklist
My suggestion meets these guidelines:
π Motivating Example
Union/Strict
is very useful for undiscriminated unions. It adds?: undefined
/?: never
properties to all the variants, soThere's just one problem:
https://codesandbox.io/s/ts-toolbelt-forked-fomds
β Suggestion
Hide
undefined | null
properties from suggestions.undefined
is more readable thanactual.bar
anyway.The text was updated successfully, but these errors were encountered: