Skip to content

QUESTION/BUG: TypeScript and default full application #321

@rodush

Description

@rodush

I'm trying to get running preact(-cli) with sass and typescript.
What I did is:

  1. created new project with --sass and --yarn flags (---type full is by default)
  2. installed preact-cli-plugin-typescript
  3. renamed .js files to .tsx files
  4. launch yarn dev and see that compilation fails because of

[at-loader] ./src/components/app.tsx:27:13
TS2559: Type '{ onChange: (e: RouterProps) => void; }' has no properties in common with type 'RouterProps & ComponentProps'.

I have 2 questions so far:

  1. What is the right way to import scss files? So far I ended with something running with
    let style = require("./style.scss"), otherwise I was getting module ./style not found during compilation (yarn dev)
    but more important:
  2. What is the correct Type/shape of event handler to be used with <Router onChange={....}>
    Does anyone check how preact works with typescript?

I can not find (via Google Search as well 😄) any explanation/example of how to deal with typescript and preact. All examples are very basic, and don't even cover the default skeleton application...

Thanks!

tsconfig.json:

{
  "compilerOptions": {
    "sourceMap": true,
    "jsx": "react",
    "jsxFactory": "h",
    "typeRoots": ["./node_modules/@types"]
  }
}
  • node --version: v8.2.1
  • npm --version: 5.3.0
  • tsc -v: Version 2.4.2
  • preact -v: preact-cli 1.4.1
  • yarn -v: v0.27.5
  • OS: Darwin Romans-MacBook-Pro.local 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64

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