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
Clean-up foo: SomeType | undefined
vs foo?: SomeType
#124362
Comments
Might also be worth to add a API-lint rule for this |
These have subtly different meanings:
We can review places where these occur in our d.ts, but coming up with a lint rule for this is probably not possible |
With TS 4.4, there's another complication: Exact Optional Property Types This means that |
Here's a draft of guidance around this: For function/method parameters:
For properties
|
…cts that we control For #124362 This includes: - Event objects - Context objects passed to providers - Managed objects such as `TextEditor`
For November, let's review classes that use Assigning owners per class:
Let me know if you have any questions about fixing these cases |
@mjbvz IIRC I did mine a couple of weeks ago. Is there something more to do? |
With exact-optional-property-types extension authors will have to provide all properties of type I think it makes sense to keep |
Since the constructors of all my assigned classes are public, changing |
@aeschli Not if the type is maintained by VS Code. It would be breaking if you make this change to an options bag object @weinand You should not change the constructor arguments but change the property. For example, export class DebugAdapterServer {
readonly port: number;
readonly host?: string;
constructor(port: number, host?: string);
} Should become: export class DebugAdapterServer {
readonly port: number;
readonly host: string | undefined;
constructor(port: number, host?: string);
} Using
|
@mjbvz sorry Matt that I did not made myself clear: |
@mjbvz Same for ThemeIcon, |
Thanks for the additional context With typescript in general, if something is typed as A few options for these cases:
These change will not break the runtime behavior of extensions. However option |
Thanks @mjbvz for looking into this and coming up with guidelines. |
@mjbvz thanks for your suggestions. Since option 1 is breaking, we cannot use it (even if we would like to encourage users to always create class instances). So I've applied option 2 in all my cases. |
Thanks. I'm going to close this and move the API guidance to a wiki I believe |
When defining optional values in object we generally prefer the question-mark notation but it seems that we aren't consistent with this. Ideally, we always use one way, min-bar should be to consistency per type, not like this
vscode/src/vs/vscode.d.ts
Lines 5600 to 5611 in 4c1474b
The text was updated successfully, but these errors were encountered: