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

undefineds not stated #1

Closed
chpio opened this issue Jul 24, 2020 · 6 comments
Closed

undefineds not stated #1

chpio opened this issue Jul 24, 2020 · 6 comments

Comments

@chpio
Copy link
Contributor

chpio commented Jul 24, 2020

Hi,

undefineds types seem to be missing in this lib.

For example, the getSelectedDocument function docs reads as:

The selected Document or undefined if no document is open.

But the undefined is still missing in the ty:

getSelectedDocument(): Document;
@qjebbs
Copy link
Owner

qjebbs commented Dec 17, 2020

There is no need to write Document | undefined, you can try to find out what is the type of d:

let d = getSelectedDocument()
function getSelectedDocument(): Document | undefined {
    return
}

@qjebbs qjebbs closed this as completed Dec 17, 2020
@chpio
Copy link
Contributor Author

chpio commented Dec 17, 2020

your code example seems to be broken. Why is there no need to define an undefined return type if it's part of the return type?

@qjebbs
Copy link
Owner

qjebbs commented Dec 18, 2020

@chpio I mean, what does it help if no lint issue raised below?

let d = getSelectedDocument()
// no lint issues
console.log(d.pages)
function getSelectedDocument(): Document | undefined {
    return undefined
}

@chpio
Copy link
Contributor Author

chpio commented Dec 18, 2020

you have to enable strictNullChecks in compilerOptions in your tsconfig. They should have enabled it by default, but i guess they refused to do so for compatibility/portability reasons with js (ts being js with optional types). Anyway... NULL being the Worst Mistake in Computer Science should encourage you to enable strictNullChecks and opt-out of implicit null & undefined.

@qjebbs
Copy link
Owner

qjebbs commented Dec 18, 2020

That makes sense, you are a TS expert. I'll add | undefined everywhere if possible, and welcome PR if you found more issues.

PS: strictNullChecks is not specified, and the default is false here (TS 4.1.2). I never noticed it.

@qjebbs qjebbs reopened this Dec 18, 2020
@chpio
Copy link
Contributor Author

chpio commented Dec 18, 2020

That makes sense, you are a TS expert.

Nah, im somewhat of an expert in rust. Rust doesn't have nulls for exactly that reason.

qjebbs added a commit that referenced this issue Dec 21, 2020
@qjebbs qjebbs closed this as completed Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants