marijnh / getdocs

Getdocs is not JSDoc
MIT License
145 stars 11 forks source link

Precise definition of "Nullable" #11

Closed bradleyayers closed 7 years ago

bradleyayers commented 7 years ago

I'd like some clarification on what does nullable mean?

Here's my understanding: (questions in bold)

  1. A nullable function parameter can accept null, or not be passed at all. Can it accept undefined?
  2. A nullable type is that type or null, e.g. both null and string match ?string, but undefined does not.

What are the rules for nullable object properties, e.g.

// :: Object<string>
const foo = {
  // :: ?"bar"
  bar: "bar",
  // :: "baz"
  baz: "baz"
};

Which of the following adhere to that type:

  1. { bar: null, baz: "baz" }
  2. { bar: undefined, baz: "baz" }
  3. { baz: "baz" }
  4. { bar: "bar", baz: "baz" }

I'm guessing 1, 3, 4.

How about class properties? e.g.

class Foo {
  constructor() {
    // :: ?string
    this.str = "";
  }
}

Can you think of any other cases that might warrant a more specific description?

marijnh commented 7 years ago

I've been using it to mean 'can be null, undefined, or missing completely', but getdocs itself doesn't assign any precise semantic meaning to it (since it's just an extractor, not any kind of type checker), and you can use it whichever way suits your style in your own projects.