Skip to content
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

Optional symbols keep their declared type #8726

Closed
wants to merge 3 commits into from
Closed

Conversation

ahejlsberg
Copy link
Member

With this PR, symbols for optional parameters, properties, and methods keep their actual declared type instead of having undefined added to the type when in --strictNullChecks mode. The undefined is added to the type in a later phase when checking expressions involving the parameter or property (specifically by checkIdentifier and checkPropertyAccessExpression). This change allows us to better preserve fidelity in declaration file emitting and also makes it possible to have different behavior for reading vs. writing of optional parameters and properties. For example, the following is now an error:

function foo(x?: number) {
    x = undefined;  // Error, declared type doesn't include undefined
}

Fixes ##8681.

@ahejlsberg
Copy link
Member Author

Thinking about this issue some more, I'm going to close this PR and put up a more localized solution.

@ahejlsberg ahejlsberg closed this May 21, 2016
@mhegazy mhegazy deleted the optionalTypes branch November 2, 2017 21:05
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants