์ฌ๊ธฐ์์ ๊ธฐ๋ฅ์ด ์์ต๋๋ค.
https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
๊ทธ๋ฆฌ๊ณ TS๋ ๊ทธ๊ฒ์ด ์ฌ์ค์ธ์ง ํ์คํ์ง ์์ ์ค๋ฅ๊ฐ ์๋ค๊ณ ๋งํฉ๋๋ค.
๊ทธ๋ฆฌ๊ณ ์ด๊ฒ์ด ์ค๋ฅ๊ฐ ์๋์ง๋ง ts๊ฐ ์ด๊ฒ์ ์ค๋ฅ๋ก ๊ฐ์ฃผํ๋ ๊ฒฝ์ฐ- @suppress ํ๋ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
๊ฐ์ฌ.
TypeScript ๋ฒ์ : 2.3.2 / ํ๋ ์ด ๊ทธ๋ผ์ด๋์์ ๋์ผ : https://www.typescriptlang.org/play/index.html
์ํธ
function uuidv4()
{
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
)
}
์์๋๋ ๋์ :
์ค๋ฅ๊ฐ ์์ต๋๊น?
์ค์ ํ๋ :
Operator '+' cannot be applied to types 'number[]' and '-1000'.
์ด๊ฒ์ ์ง์ ํฌ๋ผ์ด ์๋๋๋ค.
์ง๋ฌธ์ StackOverflow ๋๋ Gitter.im ์์ํด์ผํฉ๋๋ค.
ํ์ง๋ง ... TypeScript๋ ์์ ์ ๊ฐ์ ๋ก๋ถํฐ ๋ณดํธํ๋ฏ๋ก ๋ฐฐ์ด ๋ฆฌํฐ๋ด ์
function uuidv4()
{
- return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
+ return ([1e7] as any + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
)
}
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด๊ฒ์ ์ง์ ํฌ๋ผ์ด ์๋๋๋ค.
์ง๋ฌธ์ StackOverflow ๋๋ Gitter.im ์์ํด์ผํฉ๋๋ค.
ํ์ง๋ง ... TypeScript๋ ์์ ์ ๊ฐ์ ๋ก๋ถํฐ ๋ณดํธํ๋ฏ๋ก ๋ฐฐ์ด ๋ฆฌํฐ๋ด ์