Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

intrinsicattributes typescript

//  IntrinsicAttributes is specific to JSX
/** IntrinsicAttributes are attributes of IntrinsicElements. Intrinsic elements are 
  * looked up on the special interface JSX.IntrinsicElements. By default, if this 
  * interface is not specified, then anything goes and intrinsic elements will not be 
  * type checked. However, if this interface is present, then the name of the intrinsic 
  * element is looked up as a property on the JSX.IntrinsicElements interface.
  * The JSX.IntrinsicAttributes interface can be used to specify extra properties 
  * used by the JSX framework which are not generally used by the components’ props 
  * or arguments - for instance the key prop in React. 
  */

// Intrinsic Elements example
declare namespace JSX {
  interface IntrinsicElements {
    foo: any;
  }
}
<foo />; // ok
<bar />; // error

// Intrinsic Attributes example
declare namespace JSX {
  interface IntrinsicElements {
    foo: { requiredProp: string; optionalProp?: number };
  }
}
<foo requiredProp="bar" />; // ok
<foo requiredProp="bar" optionalProp={0} />; // ok
<foo />; // error, requiredProp is missing
<foo requiredProp={0} />; // error, requiredProp should be a string
<foo requiredProp="bar" unknownProp />; // error, unknownProp does not exist
<foo requiredProp="bar" some-unknown-prop />; // ok, because 'some-unknown-prop' is not a valid identifier
Comment

PREVIOUS NEXT
Code Example
Typescript :: convert c# class to typescript 
Typescript :: websockets socketio flask 
Typescript :: get top elements from a list python 
Typescript :: typescript compare types 
Typescript :: formgroup check if valid 
Typescript :: typescript react function coponent props 
Typescript :: chakra ui menu open on hover 
Typescript :: ts Strategy pattern 
Typescript :: import ts in html 
Typescript :: graphql server cannot be reached 
Typescript :: Scripts may close only the windows that were opened by them 
Typescript :: Interface with custom property name types 
Typescript :: typescript generics constraints 
Typescript :: python compare lists unordered 
Typescript :: typeorm schema 
Typescript :: delete array typescript 
Typescript :: typescript cast string to number 
Typescript :: classes in ts 
Typescript :: typescript annotate return type 
Typescript :: asciidots helloworld 
Typescript :: using method parameters in a guard nestjs 
Typescript :: best way to display developer credits on a website 
Typescript :: How to stop error reporting in TypeScript? 
Typescript :: how to call an action from another action slice in redux 
Typescript :: aruments in C# 
Typescript :: typescript checkbox object is possibly null 
Typescript :: when we dont have to show data of child but change in child should be displayed in parent automatically 
Typescript :: nativescript date input validation 
Typescript :: typescript dynamic array key 
Typescript :: is there somone controlling the puppets in peppermint park 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =