Skip to content

Commit

Permalink
TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsoderlund committed Jan 2, 2022
1 parent 2487c52 commit de3c495
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 14 deletions.
25 changes: 25 additions & 0 deletions Development/HTML/HTML.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,31 @@ object-size: cover;
</fieldset>
</form>

### input type

- button
- checkbox
- color
- date
- datetime-local
- email
- file
- hidden
- image
- month
- number
- password
- radio
- range
- reset
- search
- submit
- tel
- text
- time
- url
- week

### autocomplete

autocomplete="email"
Expand Down
39 changes: 25 additions & 14 deletions Development/JavaScript/TypeScript.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Compile:
tsc greeter.ts


## Organize your project

types/global.d.ts


## Types

- boolean
Expand All @@ -30,6 +35,9 @@ Compile:
- any / unknown
- null / undefined
- never
- Date
- Combined: Human & Customer
- Or: string | null

### enum

Expand Down Expand Up @@ -127,7 +135,7 @@ Function in interface:

### Nested destructuring

const { name, age }: { name: string; age: number } = personObject
const { name, age }: { name: string, age: number } = personObject

With `type`-definition:

Expand Down Expand Up @@ -160,25 +168,28 @@ With `type`-definition:

## TypeScript in React

// React.FunctionComponent alias React.FC
import React, { FunctionComponent, ReactElement } from 'react'

type MyComponentProps = {
title: string,
paragraph: string
interface MyComponentProps = {
name: string
value: number
}

const MyComponent: FunctionComponent<MyComponentProps> = ({ name, value }): ReactElement => (
const MyComponent: FunctionComponent = ({ name, value }: MyComponentProps): ReactElement => (
<div />
)
// Variants on how to declare types:
const MyComponent: React.FunctionComponent<MyComponentProps> = ({ name, value }): React.ReactElement => ()
const MyComponent: React.FunctionComponent = ({ name, value }: MyComponentProps): React.ReactElement => ()
const MyComponent = ({} : MyComponentProps) => ()
const MyComponent = ({ name } : { name: string }) => ()

const MyComponent = ({} : IMyComponent) => {}
### Important React types

// JSX.Element | null
- element/children: React.ReactNode (not JSX.Element)
- React.ReactElement
- React.FunctionComponent alias React.FC
- event: React.SyntheticEvent
- event.target: Element or HTMLInputElement

React.SyntheticEvent
useState:

const [productInfo, setProductInfo] = useState<ProductInfo>({ sku: '', name: ''})

## Tools

Expand Down
4 changes: 4 additions & 0 deletions Development/Testing and QA.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ return hasCorrectColor;

yarn add standard --dev

Use `ts-standard` if you want TypeScript:

yarn add ts-standard --dev

Use `standardx` if you want eslint (.eslintrc) config:

yarn add standardx --dev
Expand Down

0 comments on commit de3c495

Please sign in to comment.