GithubHelp home page GithubHelp logo

carhartl / typescript-cookie Goto Github PK

View Code? Open in Web Editor NEW

This project forked from js-cookie/js-cookie

47.0 2.0 6.0 2.62 MB

A simple, lightweight TypeScript API for handling browser cookies

License: MIT License

HTML 0.85% JavaScript 4.29% TypeScript 94.86%

typescript-cookie's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

typescript-cookie's Issues

Customizing getCookie return types

Is your feature request related to a problem? Please describe.
Would love to be able to add types to getCookie when I know what to expect

Describe the solution you'd like
Add generics to the signature: getCookie<KnownType>()

Describe alternatives you've considered
getCookie() as KnownType | undefined

Additional context
Not sure I'm up to it, but would be open to submitting a PR!

Cannot import library when using Jest

Describe the bug

The library works great when running my application, but fails to import when running tests with Jest. Tests fails with the error message:

Cannot find module 'typescript-cookie' from 'path/to/my/file.tsx'

I found others with the same problem on this Stack Overflow post leading me to believe it's an issue with typescript-cookie.

Additional context

I'm using the library within a project created with create-react-app. In the above linked Stack Overflow post, the other user had the same error within a project created with "VITE + TS."

Dissolve monolithic api object

With modules we can solve this with exports, no need to construct an object any longer. Will also allow for better tree-shakability, when for instance only writing cookies (?)

export { get, set, remove }

and

import * as Cookies from 'ts-cookie'

How to solve withConverter(), withAttributes() though?

Prefer `{"exports": ".

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Module not found: Error: Package path . is not exported from package

Describe the bug

An error Module not found: Error: Package path . is not exported from package /Users/ishotihadus/test/node_modules/typescript-cookie (see exports field in /Users/ishotihadus/test/node_modules/typescript-cookie/package.json) occurs when building with webpack in some cases.

I think this is caused by package.json:

"exports": {
    ".": {
      "import": "./dist/typescript-cookie.mjs",
    },
    "./package.json": "./package.json"
  },

I think there are two candidates to solve this problem.

"exports": {
    ".": {
      "import": "./dist/typescript-cookie.mjs",
      "require": "./dist/typescript-cookie.mjs",
    },
    "./package.json": "./package.json"
  },

or

"exports": {
    ".": "./dist/typescript-cookie.mjs",
    "./package.json": "./package.json"
  },

If this restriction to import is not necessary, I think the above solutions are helpful.

To Reproduce

webpack.config.ts

import * as webpack from 'webpack';

const config: (env: any) => webpack.Configuration = (env) => {
  return {
    mode: 'production',
    entry: { 'test.js': './test.ts' },
    module: {
      rules: [
        {
          test: /\.(ts|tsx)$/i,
          exclude: /(^|\/)node_modules\//,
          use: [{ loader: 'ts-loader' }]
        }
      ]
    }
  };
};

export default config;

tsconfig.json

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "commonjs",
    "strict": true,
  }
}

test.ts

import { setCookie } from 'typescript-cookie';

setCookie('hoge', 'piyio', { expires: 60, secure: true, domain: 'example.com' });

Expected behavior

Webpack can build without an error.

Error TS7016 - Could not find a declaration file

Describe the bug
If you use the new nodeResolution bundler option introduced in TypeScript 5.0 tsc will not find the declaration file for its imports and throw the following error:

error TS7016: Could not find a declaration file for module 'typescript-cookie'. 'D:/Test/.yarn/cache/typescript-cookie-npm-1.0.4-67c5369c2e-9fb4c76bd2.zip/node_modules/typescript-cookie/dist/typescript-cookie.mjs' implicitly has an 'any' type.
  There are types at 'D:/Test/.yarn/cache/typescript-cookie-npm-1.0.4-67c5369c2e-9fb4c76bd2.zip/node_modules/typescript-cookie/dist/src/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'typescript-cookie' library may need to update its package.json or typings.

1 import { getCookie, removeCookie, setCookie } from 'typescript-cookie';

To Reproduce
Steps to reproduce the behavior:

  1. Add "typescript-cookie": "^1.0.4" and "typescript": "^5.0.2" to package.json
  2. Set "moduleResolution": "bundler" in tsconfig.json
  3. Import something from 'typescript-cookie': import { setCookie } from 'typescript-cookie';
  4. Compile the file with tsc

Expected behavior
I expected tsc to find the type declaration file for 'typescript-cookie'.

Desktop (please complete the following information):

  • OS: Microsoft Windows 10 Pro 10.0.19043 Build 19043
  • Version: typescript-cookie 1.0.4

Cannot find module 'typescript-cookie' or its corresponding type declarations.

Describe the bug
Cannot find module 'typescript-cookie' or its corresponding type declarations.

To Reproduce
1.- Install the latest release v1.0.0 via: npm i typescript-cookie
2.- Import the getCookie as the documentation says
3.- VSC display error about missing library or type declarations

Expected behavior
Expect no error on a TS library about missing types. Maybe I'm doing something wrong.

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 10

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.