Fluentui: getSelectedIndices() fails strict null check

Created on 15 Apr 2018  路  5Comments  路  Source: microsoft/fluentui

Bug Report

  • __Package version(s)__: 5.80.0
  • __Browser and OS versions__: Chrome 65.0.3325.181 and Windows 10 1803

Priorities and help requested (not applicable if asking question):

Are you willing to submit a PR to fix? Yes

Requested priority: High

Products/sites affected: (if applicable)

Describe the issue:

ISelection getSelectedIndices() fails to complie due strictNullCheck in tsconfig.json.

Actual behavior:

Compilation failed with error Object is possibly 'undefined'.

Expected behavior:

Method should return an empty number array similar to getSelection() returns an empty object array

All 5 comments

馃憢 @trevonmckay

Looking at 5.82.0, getSelectedIndices seems to always return number[]. Perhaps it was patched between 5.80.0 ~ 5.82.0. Though it looks to have been untouched for awhile:

Hi @KevinTCoughlin I think the interface is what is causing the tslint strictNullChecks error.

I notice the interface is written as
getSelectedIndices?(): number[]; // TODO make non-optional on next breaking change

but the actual implementation is
getSelectedIndices(): number[]

but given there's a TODO, it appears someone is aware of it.

Raised a PR with the interface change and my understanding of the scope here.

Hi @trevonmckay, can you paste the error in its entirety from the Typescript compiler with strictNullChecks turned on, and the relevant line the error message references?

The interface that you pasted is not saying that getSelectedIndices might return undefined, but rather, that getSelectedIndices is an optional member. FWIW, we currently do have strictNullChecks enabled in OUFR at the moment.

While the breaking change of making it non-optional might help mitigate the issue you're experiencing, perhaps the fix lies in "user land"...

Going to close this as it does seem to be a user env related issue and we closed the other issue that was mentioned. Happy to re-open with add'tl context / repro.

Was this page helpful?
0 / 5 - 0 ratings