Exporting a declaration

Exporting a declaration

Any declaration (such as a variable, function, class, type alias, or interface) can be exported by adding the export keyword.

Validation.ts
1
2
3
export interface StringValidator {
  isAcceptable(s: string): boolean;
}
ZipCodeValidator.ts
1
2
3
4
5
6
7
export const numberRegexp = /^[0-9]+$/;
 
export class ZipCodeValidator implements StringValidator {
  isAcceptable(s: string) {
    return s.length === 5 && numberRegexp.test(s);
  }
}
doc_TypeScript
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.