SearchBox : TS1005 error
Bug Report
- Package version(s): checked in package-lock.json office-ui-fabric-react : 5.21.0 (but strangely i've updated it to the last version -6.62.0 something- ?) Node : 8.11.1 TypeScript : 2.4.2 sp-pnp-js : 3.0.10 react : 15.6.2
Priorities and help requested:
Are you willing to submit a PR to fix? Yes
Requested priority: Blocking
Describe the issue:
On VIsual Studio Code, when trying to add a SearchBox from office-ui-fabric-react , I get the following typescript error :
Error - typescript - node_modules\office-ui-fabric-react\node_modules@uifabric\merge-styles\lib\IStyleSet.d.ts(10,42): error TS1005: ';' expected.
Here is my truncated Didacticiel.tsx :
import * as React from 'react';
import styles from './DidacticielApplicationCustomizer.module.scss';
import { autobind } from '@uifabric/utilities/lib/autobind';
import pnp, { Sort, SearchResults, SearchQueryBuilder, SortDirection, SearchResult } from 'sp-pnp-js';
import { ApplicationCustomizerContext } from '@microsoft/sp-application-base';
import { SearchBox } from 'office-ui-fabric-react';
export interface IDidacticielProps {
modern: boolean;
listTitle:string;
webId:string;
ctx:ApplicationCustomizerContext;
}
export interface IDidacticielState {
isPanelVisible: boolean;
isVisible: boolean;
items:any[];
searchText:string;
loadingData:boolean;
}
export default class Didacticiel extends React.Component<IDidacticielProps, IDidacticielState> {
constructor(props: IDidacticielProps, state: IDidacticielState) {
super(props);
this.setState.bind(this);
this.state = {
isPanelVisible: false,
isVisible: true,
items:[],
searchText:"",
loadingData:true,
};
}
public async componentDidMount() {
this.setState({ isVisible: true });
pnp.setup({
spfxContext : this.props.ctx
});
/*Yadi Yadi Yada, I'm managing my items and getting them pushed in an array*/
}
@autobind
public render(): React.ReactElement<{}> {
return (
<div className={styles.XXX_searchContainer}>
<SearchBox
labelText="Search"
placeholder={'Make a search'}
value="Patate"
onChanged={(r) => this.setState({ searchText: r })}
onSearch={this._getListItems.bind(this)}
/>
</div>
);
}
/*My getListItems is a Promise, resolving items from a pnp.sp.search with the text being my this.state.queryText */
Here is the specific line stated in the TS1005 error in the IStyleSet.d.ts:
export declare type Omit<U, K extends keyof U> = Pick<U, Diff<keyof U, K>>;
Actual behavior:
When running gulp serve --nobrowser, my build fails and is throwing a TS1005 error :
Error - typescript - node_modules\office-ui-fabric-react\node_modules@uifabric\merge-styles\lib\IStyleSet.d.ts(10,42): error TS1005: ';' expected.
Expected behavior:
Everything working fine with no error :)
Please, did i do something wrong ?
@Amysno As of v6.59.0 (or thereabouts) there's a dependency on TypeScript 2.8+ which is the cause of your error.
But my understanding is also that v6 of this library expects React 16, and if you're using 15 you should be using version 5.x. See this comment for reference: https://github.com/OfficeDev/office-ui-fabric-react/issues/6126#issuecomment-417069604
Yes, Typescript 2.4.2 is the problem here. Using Fabric 5.x would be your best option here. We're currently backporting major bug fixes to that branch as well.
Thanks @redoz and @micahgodbolt , it was indeed all the versions causing the issue. I rolled back to previous versions and everything is working fine now ;) We'll see with the announced support of react 16 for upgrading future projects ! I'm closing it, thanks again for your time!