Skip to content

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

Closed
@MikelArnaiz

Description

@MikelArnaiz

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions