Skip to content

TypeScript doesn't allow public / private access modifiers #5584

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

Closed
MikelArnaiz opened this issue Oct 26, 2018 · 1 comment
Closed

TypeScript doesn't allow public / private access modifiers #5584

MikelArnaiz opened this issue Oct 26, 2018 · 1 comment

Comments

@MikelArnaiz
Copy link

MikelArnaiz commented Oct 26, 2018

I'm trying out the new TypeScript support. But I can't add public or private to a method
screen shot 2018-10-26 at 13 15 44

Environment

System:
OS: macOS High Sierra 10.13.5
CPU: x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
Binaries:
Node: 10.4.1 - ~/.nvm/versions/node/v10.4.1/bin/node
Yarn: 1.10.1 - /usr/local/bin/yarn
npm: 6.1.0 - ~/.nvm/versions/node/v10.4.1/bin/npm
Browsers:
Chrome: 70.0.3538.77
Safari: 11.1.1
npmPackages:
@types/react: ^16.4.18 => 16.4.18
@types/react-dom: ^16.0.9 => 16.0.9
react: ^16.6.0 => 16.6.0
react-dom: ^16.6.0 => 16.6.0
react-scripts: 2.0.5 => 2.0.5
npmGlobalPackages:
create-react-app: 2.0.4

Steps to Reproduce

Since typescript support is not yet released to npm I followed @brunolemos steps to clone CRA and link react-scripts. Then:

  1. create-react-app cra-ts-test
  2. cd cra-ts-test
  3. yarn add typescript @types/react @types/react-dom @types/jest
  4. yarn link react-scripts
  5. rename index.js to index.tsx
  6. rename App.js to App.tsx
  7. In App.tsx added public in front of render() {
  8. yarn start

Expected Behavior

It should compile and work

Actual Behavior

Failed to compile

./src/App.tsx
SyntaxError: /Users/mikel/Projects/Lab/cra-ts-test/src/App.tsx: Unexpected token (6:9)

  4 | 
  5 | class App extends Component {
> 6 |   public render() {
    |          ^
  7 |     return (
  8 |       <div className="App">
  9 |         <header className="App-header">

Reproducible Demo

https://github.com/MikelArnaiz/cra-ts-test

(make sure to yarn link react-scripts to the latest version with TS support)

@brunolemos
Copy link
Contributor

brunolemos commented Oct 26, 2018

It works fine. Please use this new method instead of yarn link:

npx create-react-app@next app-name --scripts-version=2.0.6-next.c662dfb0 --typescript

@Timer Timer closed this as completed Oct 26, 2018
@lock lock bot locked and limited conversation to collaborators Jan 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants