I notice the following syntax in Typescript.
export type feline = typeof cat;
As far as I know, type
is not a built-in basic type, nor it is an interface or class. Actually it looks more like a syntax for aliasing, which however I can't find reference to verify my guess.
So what does the above statement mean?
Use a named export to export a type in TypeScript, e.g. export type Person = {} . The exported type can be imported by using a named import as import {Person} from './another-file' . You can have as many named exports as necessary in a single file.
Introduction. Importing and exporting in React JS will help us write modular code, i.e., splitting code into multiple files. Importing allows using contents from another file, whereas exporting makes the file contents eligible for importing.
Yes, we can export the functions in TypeScript by using the 'export' keyword at the start of the function. export interface inteface_name: In TypeScript, we can export the interface as well, we can follow this syntax to make the interface exportable.
Use named exports to export multiple classes in TypeScript, e.g. export class A {} and export class B {} . The exported classes can be imported by using a named import as import {A, B} from './another-file' . You can have as many named exports as necessary in a file.
This is a type alias - it's used to give another name to a type.
In your example, feline
will be the type of whatever cat
is.
Here's a more full fledged example:
interface Animal {
legs: number;
}
const cat: Animal = { legs: 4 };
export type feline = typeof cat;
feline
will be the type Animal
, and you can use it as a type wherever you like.
const someFunc = (cat: feline) => {
doSomething(cat.legs);
};
export
simply exports it from the file. It's the same as doing this:
type feline = typeof cat;
export {
feline
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With