type script

 type script















TypeScript is a syntactic superset of JavaScript which adds static typing.

This basically means that TypeScript adds syntax on top of JavaScript, allowing developers to add types.

add what is the type to you given state

typescrit =. built type on the top of javscript

browser not understand type script

typescript => understand programm easier, debug easier




normal javacsript 


in typescript 

whle wring ing the code we know 

what is type of the state if any errors for typealso it is show

scrupt setup lang="ts"



number === '27'"

if you observe below 

ist we declared age is number , if we write string to age then it will show error 

similary for sex also




for documentation purpose
let name:string = "lATIN";

or 
let name:string;
name = 'atin";

if we declare array as number then above arry show error

declare one arrya as more data types

optional ? or string | undefined



interface ( writing type for object


sex: male or female  so fo rthis 

enum GENDER { FEMALE,MALE,NONBINARY}

sex:GENDER



NAME I SSTRING WE DECLARED 



const name = ref<string>("");


https://www.facebook.com/Silentlesson/posts/pfbid02NRi3zs3xY1A6PhoGxony3zCeE9tUGoErtdJXaUbUWWDVWeWg3Mm4tVqG8Cy4HibVl

interface Inviee {

id:number;

name:string,

string:GENDER

};
const invitees = ref<Invitee[]>([]);


const addInvitee = (name: string) => {}

addinvitee(true)=>error

addinvitee("st");


type script means validations for data type


addinvitee = (): void=> {}


types with props 

defineProps<{invitee: {id:number;name:sring;gener:}>



types with computed

https://developer.mozilla.org/en-US/docs/Glossary/Global_object




count.male

{[count.femalte}}


export these types into whole project

types.ts


export type {GENDER,type invitee}

export gender as enum value and type as value


where it is requuired

import type{GENDER,invitee} from "./types";






















No comments:

Post a Comment

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...