TypeScript declare type vs type in .d.ts
file All In One
declare type
vs type
// declare type alias
declare type API = string;
// type alias
type API = string;
demos
test.ts
=>test.d.ts
// declare type
declare type API = string;
function test(url: API){
console.log(`✅ url =`, url);
return url;
}
export default test;
test.ts
=>test.d.ts
// type
type API = string;
function test(url: API){
console.log(`✅ url =`, url);
return url;
}
export default test;
输入 | 输出 | 截图 |
---|---|---|
declare type API = string; |
declare type API = string; |
|
type API = string; |
type API = string; |
|