-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix minor typo in ko/ #217
Conversation
Translation of Modules.mdtitle: Modules translatable: trueStarting with ECMAScript 2015, JavaScript has a module concept. TypeScript shares this concept. The module runs within its own scope, not in a global scope; In other words, variables, functions, classes, etc. declared within the module are The module is declarative; The relationships between modules are specified from the file-level imports and exports perspectives. The module uses the module loader to import other modules. Like ECMAScript 2015, TypeScript uses top-level ExportExporting a declaration
StringValidator.tsexport interface StringValidator {
isAcceptable(s: string): boolean;
} ZipCodeValidator.tsimport { StringValidator } from "./StringValidator";
export const numberRegexp = /^[0-9]+$/;
export class ZipCodeValidator implements StringValidator {
isAcceptable(s: string) {
return s.length === 5 && numberRegexp.test(s);
}
} Export statementsThe Export statement comes in handy when you need to rename something to export for the user. The above example could be written as follows: class ZipCodeValidator implements StringValidator {
isAcceptable(s: string) {
return s.length === 5 && numberRegexp.test(s);
}
}
export { ZipCodeValidator };
export { ZipCodeValidator as mainValidator }; Re-export (Re-exports)Often, a module extends other modules and partially exposes some of its functionality. ParseIntBasedZipCodeValidator.tsexport class ParseIntBasedZipCodeValidator {
isAcceptable(s: string) {
return s.length === 5 && parseInt(s).toString() === s;
}
}
// 기존 validator의 이름을 변경 후 export
export {ZipCodeValidator as RegExpBasedZipCodeValidator} from "./ZipCodeValidator"; Optionally, one module can wrap one or multiple modules, AllValidators.tsexport * from "./StringValidator"; // 'StringValidator' 인터페이스를 내보냄
export * from "./ZipCodeValidator"; // 'ZipCodeValidator' 와 const 'numberRegexp' 클래스를 내보냄
export * from "./ParseIntBasedZipCodeValidator"; // 'ParseIntBasedZipCodeValidator' 클래스를 내보냄
// 'ZipCodeValidator.ts' 모듈 에 있는
// 'ZipCodeValidator' 클래스를
// 'RegExpBasedZipCodeValidator' 라는 별칭으로 다시 내보냄 ImportImport is as easy as exporting from a module. Import a single export from a moduleimport { ZipCodeValidator } from "./ZipCodeValidator";
let myValidator = new ZipCodeValidator(); You can import it by modifying the name. import { ZipCodeValidator as ZCV } from "./ZipCodeValidator";
let myValidator = new ZCV(); Import the entire module into a single variable, and use it to access the module exportsimport * as validator from "./ZipCodeValidator";
let myValidator = new validator.ZipCodeValidator(); Import a module for side-effects onlyAlthough not recommended, some modules are set to some global state so that they can be used by others. import "./my-module.js" Importing TypesPrior to TypeScript 3.8, // 동일한 import를 재사용하기
import {APIResponseType} from "./api";
// 명시적으로 import type을 사용하기
import type {APIResponseType} from "./api";
Default exportsEach module is optionally
JQuery.d.tsdeclare let $: JQuery;
export default $; App.tsimport $ from "jquery";
$("button.continue").html( "Next Step..." ); Class and function declarations can be written directly with default exports. ZipCodeValidator.tsexport default class ZipCodeValidator {
static numberRegexp = /^[0-9]+$/;
isAcceptable(s: string) {
return s.length === 5 && ZipCodeValidator.numberRegexp.test(s);
}
} Test.tsimport validator from "./ZipCodeValidator";
let myValidator = new validator(); or StaticZipCodeValidator.tsconst numberRegexp = /^[0-9]+$/;
export default function (s: string) {
return s.length === 5 && numberRegexp.test(s);
} Test.tsimport validate from "./StaticZipCodeValidator";
let strings = ["Hello", "98052", "101"];
// validate 함수 사용하기
strings.forEach(s => {
console.log(`"${s}" ${validate(s) ? "matches" : "does not match"}`);
});
OneTwoThree.tsexport default "123"; Log.tsimport num from "./OneTwoThree";
console.log(num); // "123" Export all as xIn TypeScript 3.8, when the following name is re-exported to another module, it is like a shortcut: export * as utilities from "./utilities"; If you take all the dependencies from the module and make them into exported fields, you can import them as follows: import { utilities } from "./index";
|
@microsoft-github-policy-service agree |
LGTM |
Merging because @dvlprsh is a code-owner of all the changes - thanks! |
Fix Typo