镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Update documentation to mention that --strictNullChecks flag is necessary for --strictPropertyInitialization to have an effect  #23659

Description

@loicraux

TypeScript Version:
2.7.0 and above.

Search Terms:
strictNullChecks strictPropertyInitialization

Code

class C {
    foo: number;
    bar = "hello";
    baz: boolean;

    constructor() {
        this.foo = 42;
    }
}

Expected behavior:
TS documentation should mention that --strictNullChecks flag is needed for --strictPropertyInitialization one to actually have an effect.
This would properly document the actual code change in this commit :
image
This was clearly mentionned in the corresponding PR description.
Also mihailik suggested that a warning could also be emitted. Has this been done?

Actual behavior:
This is mentioned nowhere in the documentation.
Documentation for --strictPropertyInitialization is Ensure non-undefined class properties are initialized in the constructor..
To determine if a class property is non-undefined, --strictNullChecks flag must be turned on.

Playground Link:
http://www.typescriptlang.org/play/#src=class%20C%20%7B%0D%0A%20%20%20%20foo%3A%20number%3B%0D%0A%20%20%20%20bar%20%3D%20%22hello%22%3B%0D%0A%20%20%20%20baz%3A%20boolean%20%7C%20undefined%3B%0D%0A%0D%0A%20%20%20%20constructor()%20%7B%0D%0A%20%20%20%20%20%20%20%20this.foo%20%3D%2042%3B%0D%0A%20%20%20%20%7D%0D%0A%7D%0D%0A%0D%0Aconst%20foo%3A%20string%20%3D%20%22fdsf%22%3B

Related Issues:
I found no existing issue for updating the documentation about this.

Activity

  1. changed the title [-]Update documentation to mention that `--strictNullChecks` is necessary for `--strictPropertyInitialization` to have an effect [/-] [+]Update documentation to mention that --strictNullChecks flag is necessary for --strictPropertyInitialization to have an effect [/+] on Apr 24, 2018
  2. mhegazy commented on Apr 24, 2018

    @mhegazy
    Contributor

    A PR to warn for use of --strictPropertyInitialization with no --strictNullChecks would be welcomed. The fix should be added in 'verifyCompilerOptions'.

  3. mhegazy commented on Apr 24, 2018

    @mhegazy
    Contributor

    Also a PR to update the docs would be welcomed, the handbook is at https://github.com/Microsoft/TypeScript-Handbook

  4. added
    Good First IssueWell scoped, documented and has the green light
    BugA bug in TypeScript
    DocsThe issue relates to how you learn TypeScript
    on Apr 24, 2018
  5. added this to the milestone on Apr 24, 2018
  6. a-tarasyuk commented on Apr 24, 2018

    @a-tarasyuk
    Contributor

    A PR to warn for use of --strictPropertyInitialization with no --strictNullChecks would be welcomed

    Mohamed Hegazy (@mhegazy) I'll make PR for that case.

  7. modified the milestones: , TypeScript 2.9 on Apr 25, 2018
  8. locked and limited conversation to collaborators on Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDocsThe issue relates to how you learn TypeScriptFixedA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions