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

Type mismatch is xdmp.login -- null is not assignable to undefined #18

Closed
sjordan1975 opened this issue Mar 17, 2017 · 5 comments
Closed
Assignees
Labels
Milestone

Comments

@sjordan1975
Copy link

Given the following:
xdmp.login("username", null, true, ["sa-librarian"])

Typescript validator complains:
Argument of type 'null' is not assignable to parameter of type 'string|undefined'

xdmp.login documentation: https://docs.marklogic.com/xdmp.login
xdmp.login("username", null)

@grtjn
Copy link
Owner

grtjn commented Mar 23, 2017

@christyharagan, what would you make of this?

@christyharagan
Copy link
Collaborator

Aha, this is new typing in TypeScript 2 onwards. It does a great job of disambiguating null and undefined values.

In this case, the xdmp.login function will have a signature:

(username:string, password?:string)

Where the ? means "optional" and essentially translates to the type: string|undefined.

TypeScript treats null and undefined as different values (as it should), thus the typing error.

As the current typings work, the correct usage this function is either:

xdmp.login("username")

// OR

xdmp.login("username", undefined)

If passing in null to this method is a common pattern, we could alter the typing appropriately. Happy to take suggestions on this.

@grtjn
Copy link
Owner

grtjn commented Mar 23, 2017

The docs (as referenced by OP) talk about null, not undefined, but perhaps both actually works? Using null here makes more sense to me personally too..

@rickypowell
Copy link

rickypowell commented Mar 23, 2018

So if we mark the function parameters as follows, we can accommodate both usages and avoid breaking interfaces.

(username:string, password?:string|null|undefined)

@grtjn grtjn self-assigned this Jun 26, 2018
@grtjn grtjn added the bug label Jun 26, 2018
@grtjn grtjn added this to the 0.4.0 milestone Jun 26, 2018
@grtjn
Copy link
Owner

grtjn commented Jun 26, 2018

That last comment was helpful, including this in the mL9 release..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants