This is the 12th day of my participation in the More text Challenge. For details, see more text Challenge
Declaration file
@types Official statement File Library
@types searches the declaration library
Built-in types
Built-in types
const a: Array<number> = [1,2,3] Array<number> = [1,2,3] Array<number> = [1,2,3] Array<number> = [1, 3] These files usually start with lib and end with d.ts, which tells you that I am a built-in object type const date: Date = new Date() const reg = / ABC // / we can also use build in object, built-in objects such as Math. Unlike other global objects, Math is not a constructor. All properties and methods of Math are static. Math.pow(2,2) // DOM and BOM standard object // document object, return an HTMLElement let body: HTMLElement = document.body // document Returns a nodeList type let allLis = document. QuerySelectorAll (' li ') / / add event, of course, is also a very important part of the document with the addEventListener method above, Note that the callback function, because of type inference, also automatically obtains the type of the e event object in this case, which is of type mouseEvent, because a click is a mouseEvent. Now we can easily use the methods and properties on e. document.addEventListener('click', (e) => { e.preventDefault() })Copy the code
Utility Types
Typescript also provides a number of functional, helper types that you don’t see in the JS world. These types are called Utility Types, which provide some neat and very handy features.
Interface IPerson {name: string age: number} let Viking: IPerson = {name: 'Viking ', age: 20 } type IPartial = Partial<IPerson> let viking2: IOmit = {} // Omit type IOmit <IPerson, 'name'> let viking3: IOmit = {age: 20}Copy the code
People are lazy, do not want to picture, are their own blog content (dry goods), hope to help everyone
Public number: xiao He growth, The Buddha department more text, are their own once stepped on the pit or is learned
Interested partners welcome to pay attention to me, I am: He young life. Everybody progress duck together